A Peek at Loops π
You've reached the last lesson of Level 1 β amazing work! π Here's a peek at what's coming next.
Sometimes you want to do the same thing many times. Instead of copying a line over and over, computers use a loop. This one builds up a laugh:
function laugh(times) {
let sound = "";
for (let i = 0; i < times; i++) {
sound = sound + "ha";
}
return sound;
}
laugh(3) adds "ha" three times and hands back "hahaha".
You don't have to write this yet β just read it and get the idea. In Level 2: Mini Games, you'll write your own loops, one step at a time. π