Loops Practice Quiz¶
Note that the same code fragments are used in each question below. You might find it useful to sketch out on paper what you think each code fragment will create, then match your answers with the images provided in the questions below.
Question 1¶
for (let i = 0; i < 20; i++) { line(i*2, 0, i * 15, height); }
-
Yes! Nicely done!
for (let i = 40; i > 0; i--) { rect(i * 2, i * 2, i * 2, i * 5); }
-
Try again!
let i = 0; while (i < width) { line(0, i, width, i); i += 10; }
-
Try again!
for (let i = 0; i < width; i += 10) { line(i, 0, i, height); }
-
Try again!
for (let i = 0; i < width; i++) { if (i % 15 === 0) { line(0, 0, width, i); } }
-
Try again!
for (let i = 125; i > 50; i -= 15) { rect(i, i + 50, 10, i); }
-
Try again!
let i = 50; while (i < 170) { rect(i, i + 50, i, 10); i += 20; }
-
Try again!
boolean-quiz1: Which of the following code fragments would generate the image below?
Question 2¶
for (let i = 0; i < 20; i++) { line(i*2, 0, i * 15, height); }
-
Try again!
for (let i = 40; i > 0; i--) { rect(i * 2, i * 2, i * 2, i * 5); }
-
Yes! Nicely done!
let i = 0; while (i < width) { line(0, i, width, i); i += 10; }
-
Try again!
for (let i = 0; i < width; i += 10) { line(i, 0, i, height); }
-
Try again!
for (let i = 0; i < width; i++) { if (i % 15 === 0) { line(0, 0, width, i); } }
-
Try again!
for (let i = 125; i > 50; i -= 15) { rect(i, i + 50, 10, i); }
-
Try again!
let i = 50; while (i < 170) { rect(i, i + 50, i, 10); i += 20; }
-
Try again!
boolean-quiz2: Which of the following code fragments would generate the image below?
Question 3¶
for (let i = 0; i < 20; i++) { line(i*2, 0, i * 15, height); }
-
Try again!
for (let i = 40; i > 0; i--) { rect(i * 2, i * 2, i * 2, i * 5); }
-
Try again!
let i = 0; while (i < width) { line(0, i, width, i); i += 10; }
-
Yes! Nicely done!
for (let i = 0; i < width; i += 10) { line(i, 0, i, height); }
-
Try again!
for (let i = 0; i < width; i++) { if (i % 15 === 0) { line(0, 0, width, i); } }
-
Try again!
for (let i = 125; i > 50; i -= 15) { rect(i, i + 50, 10, i); }
-
Try again!
let i = 50; while (i < 170) { rect(i, i + 50, i, 10); i += 20; }
-
Try again!
boolean-quiz3: Which of the following code fragments would generate the image below?
Question 4¶
for (let i = 0; i < 20; i++) { line(i*2, 0, i * 15, height); }
-
Try again!
for (let i = 40; i > 0; i--) { rect(i * 2, i * 2, i * 2, i * 5); }
-
Try again!
let i = 0; while (i < width) { line(0, i, width, i); i += 10; }
-
Try again!
for (let i = 0; i < width; i += 10) { line(i, 0, i, height); }
-
Yes! Nicely done!
for (let i = 0; i < width; i++) { if (i % 15 === 0) { line(0, 0, width, i); } }
-
Try again!
for (let i = 125; i > 50; i -= 15) { rect(i, i + 50, 10, i); }
-
Try again!
let i = 50; while (i < 170) { rect(i, i + 50, i, 10); i += 20; }
-
Try again!
boolean-quiz4: Which of the following code fragments would generate the image below?
Question 5¶
for (let i = 0; i < 20; i++) { line(i*2, 0, i * 15, height); }
-
Try again!
for (let i = 40; i > 0; i--) { rect(i * 2, i * 2, i * 2, i * 5); }
-
Try again!
let i = 0; while (i < width) { line(0, i, width, i); i += 10; }
-
Try again!
for (let i = 0; i < width; i += 10) { line(i, 0, i, height); }
-
Try again!
for (let i = 0; i < width; i++) { if (i % 15 === 0) { line(0, 0, width, i); } }
-
Yes! Nicely done!
for (let i = 125; i > 50; i -= 15) { rect(i, i + 50, 10, i); }
-
Try again!
let i = 50; while (i < 170) { rect(i, i + 50, i, 10); i += 20; }
-
Try again!
boolean-quiz5: Which of the following code fragments would generate the image below?
Question 6¶
for (let i = 0; i < 20; i++) { line(i*2, 0, i * 15, height); }
-
Try again!
for (let i = 40; i > 0; i--) { rect(i * 2, i * 2, i * 2, i * 5); }
-
Try again!
let i = 0; while (i < width) { line(0, i, width, i); i += 10; }
-
Try again!
for (let i = 0; i < width; i += 10) { line(i, 0, i, height); }
-
Try again!
for (let i = 0; i < width; i++) { if (i % 15 === 0) { line(0, 0, width, i); } }
-
Try again!
for (let i = 125; i > 50; i -= 15) { rect(i, i + 50, 10, i); }
-
Yes! Nicely done!
let i = 50; while (i < 170) { rect(i, i + 50, i, 10); i += 20; }
-
Try again!
boolean-quiz6: Which of the following code fragments would generate the image below?
Question 7¶
for (let i = 0; i < 20; i++) { line(i*2, 0, i * 15, height); }
-
Try again!
for (let i = 40; i > 0; i--) { rect(i * 2, i * 2, i * 2, i * 5); }
-
Try again!
let i = 0; while (i < width) { line(0, i, width, i); i += 10; }
-
Try again!
for (let i = 0; i < width; i += 10) { line(i, 0, i, height); }
-
Try again!
for (let i = 0; i < width; i++) { if (i % 15 === 0) { line(0, 0, width, i); } }
-
Try again!
for (let i = 125; i > 50; i -= 15) { rect(i, i + 50, 10, i); }
-
Try again!
let i = 50; while (i < 170) { rect(i, i + 50, i, 10); i += 20; }
-
Yes! Nicely done!
boolean-quiz7: Which of the following code fragments would generate the image below?