Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 1 to 3 using a loop.
Javascript
for(let i = 1; i [1] 4; i++) { console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' will never run the loop.
Using '==' will only run when i equals 4.
✗ Incorrect
The loop should run while i is less than 4 to print numbers 1, 2, and 3.
2fill in blank
mediumComplete the code to sum numbers from 1 to 5 using a loop.
Javascript
let sum = 0; for(let num = 1; num [1] 6; num++) { sum += num; } console.log(sum);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will exclude 5, which is needed.
Using '>' will not run the loop.
✗ Incorrect
The loop should run while num is less than or equal to 5 to include numbers 1 through 5.
3fill in blank
hardFix the error in the loop condition to print 'Hello' 3 times.
Javascript
for(let count = 0; count [1] 3; count++) { console.log('Hello'); }
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 '==' will only run once.
✗ Incorrect
The loop should run while count is less than 3 to print 'Hello' three times.
4fill in blank
hardFill both blanks to create a loop that prints even numbers from 2 to 10.
Javascript
for(let i = [1]; i [2] 11; i += 2) { console.log(i); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from 1 will print odd numbers.
Using '<=' will include 12 which is not needed.
✗ Incorrect
Start from 2 and loop while i is less than 11 to print even numbers up to 10.
5fill in blank
hardFill all three blanks to create a loop that prints numbers from 5 down to 1.
Javascript
for(let num = [1]; num [2] 0; num [3]) { console.log(num); }
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 '++' will increase instead of decrease.
✗ Incorrect
Start from 5, loop while num is greater than 0, and decrease num by 1 each time.