Variable Builder
Students edit variable values and see how output changes without rewriting every command.
More variable power
You already know a variable is a labeled box. This page adds two new tricks: boxes that hold numbers, and gluing boxes together to build sentences.
-
1
Boxes can hold numbers too
let score = 10;has no quotes — that makes it a number, not a string. Numbers can do math: if you writescore + 5, JavaScript answers 15. With quotes,"10"would just be text, like words on a sticker. -
2
Glue pieces together with
+Between strings,
+works like glue. JavaScript opens each box, takes out the value, and sticks all the pieces into one sentence:playerName+" earned "+score+" points."→ "Ari earned 10 points." -
3
Change one box, update everything
playerNameis used in both messages, but it's stored only once. Change"Ari"to your name, run the code, and watch every line update by itself. That's why coders love variables: fix a value in one place instead of hunting through the whole program.
Change the variables.
let playerName = "Ari";
let score = 10;
let badge = "Star Coder";
say(playerName + " earned " + score + " points.");
say(playerName + " unlocked: " + badge);
Program result
- Run your code to see output.
Type real JavaScript, then run it.
You changed stored values and watched the program output update.
Try Variable Challenge