Implement the function startCountdown(n)
using setInterval
.
It should print to the console all number from n
to 1 and then the string GO!
.
The delay between calls to the console.log
should be 0.1 second.
The interval should be cleared once all the output was processed.
Different countdowns should be independent of each other.
This task is part of the Full-Stack JavaScript Course
If you have any issues with it, you can ask for community help below the post
Feel free to help others if you’ve already solved the task
functions.js
export const startCountdown = (n) => {
setInterval(() => {
let i = 0;
if (i < n) {
console.log(n - i);
i++;
} else {
console.log('GO!');
}
}, 1000)
}
solution.js
/**
* Implement the function startCountdown(n)
*
* It should print to the console all number from `n` to 1 and then the string `GO!`.
*
* The delay between `console.log` calls should be 0.1 second.
*
* */
import { startCountdown } from './functions.js';
startCountdown(5);