M
If by paragraph:Functions area(), perm(), size() not accepting any parameters, calling them onclick="area(width,height)" It doesn't make sense, because at the time of the challenge, there is no memory.Data, sort of width You're trying to get your own function in the body, causing a blocking function. prompt()that's not exactly the right thing to do. The JavaScript script environment offers many excellent opportunities to obtain user data. For example, with help input type="number"♪ Moreover, the result of the challenge prompt() There's nowhere to be stored. So I wrote:let height = +prompt("height");Where I enter, a local variable for the function, which will accept the return. Drug operator + converts the line (if possible) to number.Telework area() other functions result()but the result of her challenge is not accepted. I'll do it. result() It doesn't come back. Moreover, the function and intended return have the same name. result♪ You could have declared a variable. result in the global field, but in an attempt to give it meaning in the body of a single function (result = prompt("want to see result?")there will be a conflict of names and a violin will end in a mistake. It is therefore better to call a function: getResult, countArea, doSomething, one word.
In your version, in part. switch (result) variable result keeps a reference to function as an object.
So I'm reintroducing the local variable. resultin which the function is returned getResult() meaning. Although with the same success, one can briefly describe switch(getResult())♪The challenge itself. prompt() to confirm the conclusion of the result is also doubtful. No options proposed 'y' or 'n'that information can only be found from the code. Then you better use it. confirm()♪ Although neither prompt nor confirm nor alert should be fully used under any circumstances.Don't fight hard. I left the author's logic, only led to a minimum working option.function getResult(){
return prompt("want to see result?"); // Возвращается значение, введенное пользователем
}
function area() {
let height = +prompt("height"); // Принимаем значение, преобразовываем в Number и присваиваем переменной
let width = +prompt("width?");
let result = getResult(); // Принимаем, возвращаемое функцией, значение
switch (result) {
case "y":
alert(height * width)
break;
case "n":
alert("ok")
break;
default:
break;
}
}<button onclick="area()">AREA</button> <!--Сократил немного -->