Back to Variable Builder
Code Studio · Level 2

Variable Challenge

Create at least two variables, then use them in say() commands.

10-15 min Ages 9-12 Challenge JavaScript

Variable rules to remember

The recipe is always the same: let label = value; — make a box, write the label, put something inside. Before you write your own, here are the rules real JavaScript coders follow.

  1. 1

    Label names have rules

    No spaces allowed! Coders squish words together and capitalize each new word: petName, favoriteFood, highScore — that style is called camelCase (the bumps look like camel humps). Capital letters matter too: petName and petname are two different boxes.

  2. 2

    Watch out for these bugs

    Quotes go around the value, never the label — say(petName) opens the box, but say("petName") just says the word petName. And you must make a box before you use it: if you say(petName) without a let petName = ... line first, JavaScript stops and reports an error.

  3. 3

    Your challenge missions

    Make at least two boxes of your own and use them in say() commands. Want more? Try three boxes about yourself — name, age, favorite food — then glue them into one sentence with +, like say(myName + " is " + age);. Then swap a value and run it again.

Code Editor

Write your own variables.

Example code
let petName = "Pixel";
let petPower = "laser purr";

say(petName);
say(petPower);
Output

Program result

Robot ready to speak your strings

Type real JavaScript, then run it.