Please answer each of these questions by clicking on the circled letters. At the end, please click on the "Mark Answers" button to see how you did.
a = 10; do { a /= 2; y = a * 10; } while (a < 1); |
0.625 1 1.25 5 10 |
for (x = 1; x < 10; x++) for (y = 1; y < 5; y++) document.write("Hello!"); |
36 40 45 50 The program does not give us enough information to work it out. |
do { s = prompt("Please enter a number",""); n = parseFloat(s); } while (n < 40 || n < 50); |
A number smaller than 40 is entered. A number bigger than 50 is entered. A number bigger than 40 is entered. A number smaller than 50 is entered. A number between 40 and 50 is entered. |
while loops only while loops and do-while loops for loops only do-while loops only for loops and do-while loops |
for (count = 0; count < 31; count+=2) |
15 16 30 31 We cannot tell just from the line given above. |
a = 6; while (a < 1000) document.write("The value of a is " + a + "<p />"); a *= 10; alert("The loop has terminated"); |
The loop displays three values for a, namely 6, 60 and 600. The loop displays four values for a, namely 6, 60, 600 and 6000. The loop runs forever (until the browser is shut down). The browser reports an error because there are no curly brackets. The loop doesn't execute even once. |
do { var *= 20; temp += var; } while (temp < 1);
while (n < 1 || n > 10) { s = prompt("Enter a number from 1 to 10",""); n = parseFloat(s); } do { s = prompt("Enter a number from 1 to 10",""); n = parseFloat(s); } while (n < 1 || n > 10); s = prompt("Enter a number from 1 to 10",""); do { n = parseFloat(s); } while (n < 1 || n > 10); while (n >= 1 && n <= 10) { s = prompt("Enter a number from 1 to 10",""); n = parseFloat(s); } do { s = prompt("Enter a number from 1 to 10",""); n = parseFloat(s); } while (n >= 1 && n <= 10); |
for (count = 1; count != 20; count++) { alert("Count is " + count); count++; }
the variable count is always less than 20. the condition part of the loop is always true. the variable count is always greater than 20. JavaScript does not allow you to alter the value of count within the body of the loop. the condition part of the loop fails the first time that it is tested. |
var x = 10; var y = 0; while (x > 0) { y += x; x--; } document.write("The answer is " + y);
It counts down from 10 to 0. It counts up from 0 to 10. It counts down from 10 to 1. It adds all the whole numbers from 0 to 10. It adds all the whole numbers from 1 to 10. |