0
0
Javascriptprogramming~10 mins

Why loop control is required in Javascript - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A>=
B>
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < causes the loop to never run.
2fill in blank
medium

Complete 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'
A==
B!=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using != will break the loop for all values except 3.
3fill in blank
hard

Fix 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'
A>
B==
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using != will skip all values except 2.
4fill in blank
hard

Fill 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'
A<
B++
C+=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > will cause the loop to never run.
Using += without a number is invalid.
5fill in blank
hard

Fill 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'
A10
B>
C--
D<
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.