Skip to main content
🌱 Coding Level 1: First Steps 🌱

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. πŸ‘‡

What does laugh(3) hand back?

A loop is handy when you want to:

What's next for you?

Answer every question to complete the lesson.