๐Ÿ“–
Code Studio ยท Ages 9โ€“12

Choose-Your-Path Story

First play a branching story, then rebuild it with real JavaScript. You'll snap together functions like scene(), show(), and onPick(โ€ฆ goTo โ€ฆ), and carry a variable across scenes to decide what the player sees.

The big idea

A choose-your-path story is built from three small pieces that repeat.

๐ŸŽฌSceneSomething is happening
๐Ÿ”€Choices2 or more buttons
โžก๏ธGo toEach pick leads on

Read it out loud and it sounds like code: โ€œIf the player picks the blue door, then go to the control room.โ€ That word if is the engine of every game.

How one scene branches

One scene can split into two paths. Follow the lines.

๐ŸŽฌ Scene: A quiet moon base
Pick: Blue door
๐ŸŽฌ Control Room
Pick: Red door
๐ŸŽฌ Glow Garden
// one scene, two choices
if (choice === "blue door") {
  goToScene("controlRoom");
}
if (choice === "red door") {
  goToScene("glowGarden");
}
Play it first

The Moon Base Mystery

Your robot friend Pixel is missing. Make choices to find Pixel. There are three different endings!

This is the code running the scene you're on right now:

Now you code it ยท Part 1 of 2

Code Lab: build The Moon Base Mystery

You just played the story โ€” now rebuild it with code using the real chunks. Each scene() has a name, and a choice uses onPick(โ€ฆ goTo โ€ฆ) to jump to another scene by its name. Click a block to add it, drag to reorder, then press Run code to play it.

๐Ÿงฑ Function blocks

The whole story's blocks โ€” pick only the ones your mission needs.

๐Ÿ“ Your program

Runs from top to bottom.