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

Red Light, Green Light 🚦

Now you write the choice yourself! A traffic light tells cars when to go and when to stop.

You can drag the blocks in (in order) instead of typing from scratch, or tap the hint to fill it in step by step.

if (color === "green") {
  return "go";
} else {
  return "stop";
}

Your task

Write light(color). If color is exactly "green", return "go". Otherwise, return "stop".

⚑ 25 XP

🧱 Code blocks

Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.

solution.jsRuns in your browser
Loading editor…
Tests3 to pass
"green" β†’ "go"
"red" β†’ "stop"
"yellow" β†’ "stop"

Run your code to check these.