Variable Challenge
Finish the basketball game by coding the visiting team's winning shot.
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
The final-game variables
The Comets lead the Rockets 44–43. The Rockets have possession, and
shotPointsshould store 2. Keep the camelCase variable names exactly as written so the scoreboard knows which boxes to open. -
2
Update the correct score
The visiting team is shooting, so update
visitingScore, nothomeScore. Read its old value, addshotPoints, and store the new total back in the same variable. -
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.
Complete the final possession.
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;
Final possession
00:05
COMETS
ROCKETS
44
43
4
4
4
◀
Rockets need 2 points to win!
- Run your code to see output.
Type real JavaScript, then run it.
You created game variables, updated a score, and completed the basketball game.
Next Lesson