Loop Challenge
Write a real JavaScript loop that prints at least three messages.
Loop rules to remember
The recipe: for (start; keep going; add 1) { repeat this } — three
instructions in the parentheses, separated by semicolons, and the
repeated code inside the braces.
-
1
The counter must grow
The
step++part is what moves the loop forward. Forget it, and the counter stays at 1 forever — the loop never ends and the program gets stuck running in circles. Always check: start, limit, and the add-one. -
2
Semicolons inside, braces outside
The parentheses hold the three parts split by
;— and the same counter name must appear in all three. Then the braces{ }wrap whatever should repeat, just like the "then" part of anif. -
3
Your challenge missions
Write a loop that prints at least three messages using the counter. Bonus mission: make a rocket countdown! Start the counter high and shrink it with
--:for (let n = 5; n >= 1; n--)prints 5, 4, 3, 2, 1 — then add one moresay("Liftoff!")after the closing brace.
Write your own loop.
for (let step = 1; step <= 3; step++) {
say("Robot step " + step);
}
Program result
- Run your code to see output.
Type real JavaScript, then run it.
You wrote a real JavaScript loop that repeats output.
Next Lesson