+ 2
JS Please help "Multiplication a number"
Hello I try to make something to multiplication numbers. At start something simple. if there is no numbers on the inbox then a loop must occur. When it failed i write a code only to show a score. also don't work :/ <script type = "text/JavaScript"> alert("Please enter correct numbers for multiplication"); var a = prompt("Give first numbers: "); var b = prompt("Give a second numbers: "); var score = a * b; if(isNaN(score){alert("Please give only a numbers!"); else{document.write(score)}; </script>
4 Respostas
+ 3
Errors in your code:
-is missing a relatives to close the if.
-The semicolon in the document.write is in the wrong place.
-when there is only one statement after the if / else the {} are optional.
learn to indent your code, it becomes easier to understand it.
+ 4
The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML. Use innerHTML instead.
+ 2
alert("Please enter correct numbers for multiplication");
var a = prompt("Give first numbers: ");
var b = prompt("Give a second numbers: ");
var score = a * b;
if(isNaN(score))
alert("Please give only a numbers!");
else
document.write(score);
+ 1
It works!... but how?! In all my books it's written "when You use "if" it can be "if (condition){something}; else{something};"