Sunday , September 8 2024

In the following code fragment, where we use setInterval, one line is missing – the place is marked in gray: let counter = 2; let interval = setInterval(() => { console.log(counter); }, 1000); What should the missing line look like if the execution of this code results in the console displaying the values 2, 1, and 0 in sequence?

Questions BankCategory: JavaScript Essentials 1In the following code fragment, where we use setInterval, one line is missing – the place is marked in gray: let counter = 2; let interval = setInterval(() => { console.log(counter); }, 1000); What should the missing line look like if the execution of this code results in the console displaying the values 2, 1, and 0 in sequence?
In the following code fragment, where we use setInterval, one line is missing – the place is marked in gray:

let counter = 2;
let interval = setInterval(() => {
    console.log(counter);

}, 1000);

What should the missing line look like if the execution of this code results in the console displaying the values 2, 1, and 0 in sequence?

  • if (counter-- <= 0) clearInterval(interval);
  • while (counter-- >= 0) clearInterval(interval);
  • clearInterval(interval);
  • if (counter-- >= 0) clearInterval(interval);

More Questions: JavaScript Essentials 1 – JSE1: Final Test