Variable Challenge
Create at least two variables, then use them in say() commands.
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
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:petNameandpetnameare two different boxes. -
2
Watch out for these bugs
Quotes go around the value, never the label —
say(petName)opens the box, butsay("petName")just says the word petName. And you must make a box before you use it: if yousay(petName)without alet petName = ...line first, JavaScript stops and reports an error. -
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+, likesay(myName + " is " + age);. Then swap a value and run it again.
Write your own variables.
let petName = "Pixel";
let petPower = "laser purr";
say(petName);
say(petPower);
Program result
- Run your code to see output.
Type real JavaScript, then run it.
You created variables and used them in real JavaScript.
Next Lesson