Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a loop that runs 5 times.
Javascript
for(let i = 0; i [1] 5; i++) { console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < causes the loop to never run.
✗ Incorrect
The loop should run while i is less than 5, so it runs 5 times from 0 to 4.
2fill in blank
mediumComplete the code to stop the loop when i equals 3.
Javascript
for(let i = 0; i < 5; i++) { if(i [1] 3) { break; } console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != will break the loop for all values except 3.
✗ Incorrect
The loop should stop when i is equal to 3, so we use == to check equality.
3fill in blank
hardFix the error in the loop to skip printing when i is 2.
Javascript
for(let i = 0; i < 5; i++) { if(i [1] 2) { continue; } console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != will skip all values except 2.
✗ Incorrect
To skip printing when i is 2, use == to check equality and continue the loop.
4fill in blank
hardFill both blanks to create a loop that prints only even numbers from 0 to 8.
Javascript
for(let i = 0; i [1] 10; i[2]) { if(i % 2 === 0) { console.log(i); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using > will cause the loop to never run.
Using += without a number is invalid.
✗ Incorrect
The loop runs while i is less than 10 and increments by 1 each time using ++.
5fill in blank
hardFill all three blanks to create a loop that prints numbers from 10 down to 1.
Javascript
for(let i = [1]; i [2] 0; i[3]) { console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 0 will not print the numbers down to 1.
Using < will cause the loop to never run.
✗ Incorrect
The loop starts at 10, runs while i is greater than 0, and decreases i by 1 each time using --.