I need help with JavaScript

Asked By 10 points N/A Posted on -
qa-featured

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>

SHARE
Answered By 0 points N/A #94665

I need help with JavaScript

qa-featured

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?

Related Questions