Write a code that displays the result of multiplying numbers from 1 to 10 by 5.

What am I doing wrong?

var x = 5; var y = 1; var z = x * y; while (z <= 50) { document.write(x + "x" + y + "=" + z + "<br>"); y++; } 

Closed due to the fact that off-topic by user207618, pavel , cheops , Denis , aleksandr barakin participants 21 Oct '16 at 7:15 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - community spirit, pavel, cheops, Denis, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    Calculate z move inside the loop. - Visman
  • thanks, now it works - Anna Kukhareva

3 answers 3

 var x = 5, y = 1, z; while (z < 50) { z = x * y; document.write(x + "x" + y + "=" + z + "<br>"); y++; } 

But, judging by the task, the result of the multiplication is not known in advance, therefore it is more correct to check not by the result, but by the value of the variable that will be multiplied:

 var x = 5, y = 1; while (y <= 10) { z = x * y; document.write(x + "x" + y + "=" + z + "<br>"); y++; } 
  • what is the meaning var z = ""; ? why even a string? - Grundy
  • @Grundy blundered. corrected - lexxl
  • no, it turns out that it is necessary to assign a value before checking, otherwise the cycle may not even start. Means a cycle in which z checked. When checking y variable z is not needed at all - Grundy
  • @lexxl is fine, now everything works, thanks :) - Anna Kukhareva
  • @Grundy thanks, that's clearer) - Anna Kukhareva

Write a code that displays the result of multiplying numbers from 1 to 10 by 5

By assignment it is clear that you need to withdraw 1 * 5.2 * 5.3 * 5 ... 10 * 5.

 var i = 0; while(i<10){ i++; console.log(i*5); } 

    If I understand the condition correctly then so :)

     var i =1; while (i<11){ console.log(i*5); i++ } 

    The output will be in the browser console

    • using the while loop - Grundy