Counting Down the Seconds
You are a timekeeper tasked with overseeing a magical hourglass that counts down the seconds. Your job is to create a function that will display a countdown from a given number of seconds to zero. The countdown should be displayed one second at a time.
Write a function named countdown
that takes one parameter seconds
that represents the number of seconds to count down from. After the countdown reaches zero, print "Time's up!".
Example 1
Input: countdown(5);
Output:
5
4
3
2
1
0
Time's up!
Example 2
Input: countdown(0);
Output:
0
Time's up!
Example 3
Input: countdown(3);
Output:
3
2
1
0
Time's up!
Are you stuck on this problem?
Get detailed, step-by-step solution and improve your JavaScript skills.
- Detailed Explanation: Each solution comes with a comprehensive explanation, helping you understand the logic and concepts thoroughly.
- Learn to Write Better Code: Even if you have written the code, discover ways to improve it and adopt best practices.
- Save Time: Don’t waste hours struggling—get the solution and learn efficiently.
- Lifetime Access: Get access to lifetime solutions for all problems available
" I struggled with this problem for hours, but the solution provided here was clear and easy to follow. It helped me understand where I went wrong and improved my coding skills significantly." - Jane D.
If you're not satisfied, I offer a 7-day money-back guarantee.