Back to Variable Builder
Code Studio · Level 2

Variable Challenge

Finish the basketball game by coding the visiting team's winning shot.

10-15 min Ages 9-12 Challenge JavaScript

Variable rules to remember

You created the scoreboard, then updated a score after a basket. For the final challenge, use those same skills with fewer hints and make the game end correctly.

  1. 1

    The final-game variables

    The Comets lead the Rockets 44–43. The Rockets have possession, and shotPoints should store 2. Keep the camelCase variable names exactly as written so the scoreboard knows which boxes to open.

  2. 2

    Update the correct score

    The visiting team is shooting, so update visitingScore, not homeScore. Read its old value, add shotPoints, and store the new total back in the same variable.

  3. 3

    Announce the final result

    Use say() to show both final team scores. When the Rockets reach 45, the court will play the winning shot and unlock the next lesson.

Code Editor

Complete the final possession.

Mission

Rockets trail 44–43. Add the missing update line so their 2-point shot changes visitingScore to 45.

Hint: Follow the pattern from Variable Builder: score = score + points;

Output

Final possession

Basketball scoreboard 00:05 COMETS ROCKETS 44 43 4 4 4
Basketball hoop Basketball Rockets need 2 points to win!

Type real JavaScript, then run it.