javascript · level 1 · unit 2 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Put something new in a box and the old thing is gone.
A box holds one value at a time. Store a new value and you the old one, like wiping a whiteboard. Leave out let this time: the box already exists, so you only change what is inside.
The + sign can two strings into one: "pop" + "corn" makes "popcorn". It adds no space, so put one inside the quotes if you need it.
Some values should never change, like your birthday. Make those boxes with instead of let. Try to overwrite one and JavaScript stops with a .
let mood = "sleepy";
mood = "happy";
console.log("I feel " + mood);
const birthday = "12 May";
console.log("My birthday is " + birthday); Use let for boxes that will change and const for boxes that never will.
guess first
A locked box. What happens here?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
const pet = "Rex";
console.log(pet);
pet = "Max";
console.log(pet);
your turn
Your turn. Change the weather.
Line 3 puts a new value in the weather box. Type tomorrow's weather between the quotes, then press run.
fix it
The score will not update. Can you fix it?
- Read the error. JavaScript is unhappy that the same box is being made twice.
letmakes a brand new box. After line 1, the box called score already exists.- Remove
letfrom line 2, so it reads score = 20; then press run.
nailed it
your boxes can change now. :D
- A new value overwrites the old one. No second
let. +joins strings, with no space added.constboxes never change. Useletfor ones that will.
new words in your collection
- overwrite
- join
- const
- TypeError
This lesson isn’t saved. A free account remembers every lesson you finish.