💻 TechnologyGrade 5Lesson 30
← Back🔒 PDF with full access

Code a Story or Quiz

Lesson preview: the Mini Lesson and Vocabulary are open to everyone. Guided practice, exercises, the parent checklist and the printable PDF worksheet come with full access (free 7-day trial or membership).

What you will learn

  • 1Plan a branching story or quiz with clear choices and outcomes
  • 2Connect a player’s choice to the right trigger or response
  • 3Use scoring, hints, and endings to keep players engaged
  • 4Spot branches that lead nowhere and explain how to fix them
📘

Mini Lesson

A story or quiz becomes a CODE PROJECT when the reader gets to make choices. Every choice opens a branch, and every branch leads to an outcome. Your job as the coder is to plan those branches before you build them — so no path leads to a dead end.

How a Branching Project Works

A branching project follows a simple loop: show something, ask the player to choose, then jump to whatever happens next. That happens-next part starts with a TRIGGER: the moment a choice or event happens, which makes the next lines of code run.

  1. Show — display a screen, a question, or a story line.
  2. Choose — let the player click a button, type an answer, or pick a path.
  3. Trigger — the chosen action fires the matching code (jump, score, hint, ending).
  4. Repeat or end — loop to the next screen, or stop the game with a result.

Story Branches vs Quiz Logic

Stories use branches to give the reader choice — pick A, pick B, see different endings. Quizzes use logic to score answers — right answers add to the score, wrong answers show a hint. Both ideas are coded the same way: an IF-THEN rule that listens for the player and triggers a response.

  • Branch — a path the player can take. Each branch leads somewhere.
  • Choice — the button or input the player picks to take a branch.
  • Outcome — what happens at the end of a branch (a scene, a score, a screen).
  • Score — a number that tracks correct answers or progress.
  • Ending — the final screen the player sees (win, lose, retry, happy ending).

Plan Before You Code

Sketch the branches on paper first. Write the topic, the opening line, the two choices, what each one leads to, and the ending. If you can read the plan out loud and it makes sense, the code will too. If the plan has a path with no outcome, fix it BEFORE you open the editor.

Words to know

branch

A path the player can take in a story or quiz; each branch leads somewhere different.

choice

The button or input a player picks to follow a branch.

outcome

What happens at the end of a branch — a scene, score change, or ending screen.

score

A number that tracks correct answers or progress in the project.

ending

The final screen the player sees — win, lose, retry, or a kind closing line.

Branching Story TreeBranching Story TreeSTARTchoice Achoice BBRANCH ABRANCH BOUTCOME Ahappy endingOUTCOME Bretry screenevery branch needs an outcome
Quiz Logic FlowQuiz Logic FlowQUESTIONANSWER?correct or not?correctSCORE +1wrongHINTNEXT Qloop until score reaches the goal
💡

Tip: walk through every branch as the player BEFORE you call the project done. If you find a button that does nothing, that is a bug — fix it now, not later.

Free · 7 days · No credit card

Unlock the full HSEA system for 7 days.

Add your first kid profile and your 7 days start: every lesson in every grade, saved progress for each child. Nothing to set up, no card required, nothing to cancel.

  • ✓ All 1,880 lessons, Grades 1–6, every subject
  • ✓ Profiles + saved progress for every kid
  • ✓ Printable lessons with answer key
Start your 7-day free trial →
← Lesson 29: Sensors & Robots (Intro)Lesson 31: Coding Review & Refactor →