Hi guys ,please help me to find the output of this JavaScript code,
<html>
<body>
<script type="text/javascript">
var x=0;
while(x != “”){
r = prompt("Enter a number?");
document.write('square(' + x + ') = ' + x*x + '<br>');
}
</script>
</body>
</html>
I need help with JavaScript
Hi robbie, I don't think your code will run,I have several issues with it
While loop
Syntax
While (variable<=endvalue)
{
code to be executed
}
Check out the following code.
Please copy and paste it on a notepad and save as yourname.html
Then run.
<html>
<body>
<script type="text/javascript">
var i=0;
while (i<=5)
{
document.write("The number is " + i);
document.write("<br />");
i++;
}
</script>
</body>
</html>
For your case you need to pass the integer r and not x, thirdly,when you do the necessary modification,the output should be: Enter a number? /*when you enter the number for our case lets say enter 2 */ Square x = 4
Thank you. Was this helpful to you?