Loop Builder
Students change the counter, repeat limit, and output message in a real JavaScript loop.
Loop power-ups
You know the loop recipe: for (start; keep going; add 1) { repeat this }.
This builder mixes loops with everything else you've learned — variable boxes, glue,
and counters with better names.
-
1
Name your counter anything
iis just a popular nickname. This example counts withcount— you could usestep,lap, orstarNumber. Pick a label that says what you're counting, and use the same name in all three parts of the recipe. -
2
Loops + variables + glue, all together
say(action + " " + count)opens theactionbox, glues it to the counter, and prints "Collect star 1", "Collect star 2"... Change the value in theactionbox once, and every line of output changes. -
3
Experiment with the numbers
Make it count to
8. Make it start at3— how many lines print now? Predict first, then run. (Starting at 3 and stopping at 4 gives just two laps: 3 and 4.)
Customize the repeat.
let action = "Collect star";
for (let count = 1; count <= 4; count++) {
say(action + " " + count);
}
Program result
- Run your code to see output.
Type real JavaScript, then run it.
You changed a loop and saw the repeated output update.
Try Loop Challenge