Back to Message Challenge
Code Studio · Level 2

Real JavaScript Variables

Teach the robot to remember. Variables are labeled boxes that store names, scores, and powers — fill a box once, and your code can use it everywhere.

15-20 min Ages 9-12 Real Code JavaScript

What is a variable?

A variable is like a labeled box. You write a name on the outside, put a value inside, and close the lid. From then on, whenever your code uses the name on the label, the computer opens the box and grabs whatever is inside. The label stays the same — but you can swap what's in the box any time.

"Mia" heroName
  1. 1

    Make the box: let heroName = "Mia";

    let tells JavaScript "make a new box." heroName is the label you write on it. = means "put this inside," and "Mia" is the value that goes in the box.

  2. 2

    Use the label, get what's inside

    say(heroName) makes the robot say Mia — not "heroName." There are no quotes around it, so the computer knows it's a box label and opens the box to find the value.

  3. 3

    Why coders use them

    Variables let a program remember things — a player's name, a score, a power. And if your hero's name appears 20 times in a game, you only change the box once and every spot updates. Try it: change "Mia" to your own name and run the code again.

Code Editor

Create and use a variable.

Example code
let heroName = "Mia";
let power = "moon jump";

say(heroName);
say(power);
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.