0
0
Javascriptprogramming~15 mins

While loop in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Counting Down with a While Loop
📖 Scenario: Imagine you have a countdown timer for a game or event. You want to count down from a starting number to zero, showing each number as it counts down.
🎯 Goal: You will create a program that uses a while loop to count down from a given number to zero and print each number.
📋 What You'll Learn
Create a variable called count with the starting number 5
Create a variable called limit with the value 0
Use a while loop that runs as long as count is greater than or equal to limit
Inside the loop, print the current value of count
Inside the loop, decrease count by 1 each time
💡 Why This Matters
🌍 Real World
Counting down is useful in timers, games, and event reminders where you want to show time left.
💼 Career
Understanding loops is essential for programming tasks like automation, data processing, and controlling program flow.
Progress0 / 4 steps
1
Set up the starting number
Create a variable called count and set it to the number 5.
Javascript
Need a hint?

Use let count = 5; to create the variable.

2
Set the countdown limit
Create a variable called limit and set it to 0.
Javascript
Need a hint?

Use let limit = 0; to create the limit variable.

3
Create the while loop to count down
Write a while loop that runs as long as count is greater than or equal to limit. Inside the loop, print the value of count and then decrease count by 1.
Javascript
Need a hint?

Use while (count >= limit) { ... } and inside the loop use console.log(count); and count--;.

4
Display the countdown
Run the program to print the countdown numbers from 5 to 0.
Javascript
Need a hint?

Check the console output shows numbers from 5 down to 0, each on its own line.