Back to Loop Builder
Code Studio · Level 4

Loop Challenge

Write a real JavaScript loop that prints at least three messages.

10-15 min Ages 9-12 Challenge JavaScript

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. 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. 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 an if.

  3. 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 more say("Liftoff!") after the closing brace.

Code Editor

Write your own loop.

Example code
for (let step = 1; step <= 3; step++) {
  say("Robot step " + step);
}
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.