Making Choices
Branch the story.
Making Choices is a free Javascript for Kids lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Javascript for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Choose Your Path! 🌿
The BEST part of an adventure game: choices! Go left or right? Open the door or run? Let us make the story branch! 🛤️
A Simple Choice 🤔
Store the player choice in a variable, then react to it with if.
let choice = "left"
if (choice === "left") {
console.log("You go left into a sunny meadow! 🌼")
}Two Paths with else 🔀
What if they go right instead? else handles the other path!
let choice = "right"
if (choice === "left") {
console.log("Sunny meadow! 🌼")
} else {
console.log("You go right into a spooky cave! 🦇")
}Three Choices with else if 🔢
More paths? Use else if for a third (or fourth) choice!
let choice = "up"
if (choice === "left") {
console.log("Meadow!")
} else if (choice === "up") {
console.log("You climb a tall mountain! ⛰️")
} else {
console.log("Cave!")
}Choices Lead to More Choices 🌳
One choice opens new ones! This makes the story grow like a tree.
let path = "cave"
if (path === "cave") {
console.log("Inside the cave you see two tunnels! 🦇")
console.log("Type left or right to continue...")
}Picking Up Items 🎒
Let the player choose to grab a treasure! Add it to their bag.
let bag = []
let choice = "take sword"
if (choice === "take sword") {
bag.push("sword")
}
console.log("Your bag:", bag)Choices Change the Story 📖
Different choices give different story text. The player feels in control!
let choice = "open"
if (choice === "open") {
console.log("The door creaks open... treasure! 💰")
} else {
console.log("You walk away and miss the gold. 😢")
}A Choice Function 🛠️
Make a helper that handles a choice. Reuse it at every fork in the road!
function go(direction) {
if (direction === "north") {
console.log("You head north to the castle! 🏰")
} else {
console.log("You head into the woods. 🌲")
}
}
go("north")Lucky or Unlucky? 🎲
Add surprise! Random events make every play different.
let luck = Math.floor(Math.random() * 2)
if (luck === 1) {
console.log("You found a hidden coin! 🪙")
} else {
console.log("Nothing here... keep going. 🚶")
}Remembering Choices 🧠
Store choices so the story remembers what the player did!
let choices = []
choices.push("went left")
choices.push("took the sword")
console.log("So far you:", choices)Branching Works! ✅
Your story now branches based on player choices, picks up items, and even has lucky surprises. So interactive! 🎮
let choice = "left"
if (choice === "left") {
console.log("Adventure continues to the left! ➡️")
} else {
console.log("A new path opens! 🌟")
}Quick Check ❓
Choose the right answer! 🧠
Choice Champion! 🏅
Recap! You learned to:
- 🤔 React to a choice with
if - 🔀 Add paths with
elseandelse if - 🎒 Pick up items into a bag
- 🎲 Add random surprises
Next: WINNING the adventure! 🏆
Frequently asked questions
Is the “Making Choices” lesson free?
Yes — the full text of “Making Choices” is free to read here on the web, and the Javascript for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Javascript for Kids course, upgrade to CoddyKit PRO.
What will I learn in “Making Choices”?
Branch the story. You practise Javascript for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Javascript for Kids?
No prior experience is required. Javascript for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Making Choices” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Javascript for Kids lesson?
Yes. Every Javascript for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Planning the Adventure
- Making Choices
- Winning
- Game Over