typescript · 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.
Boxes made with let can change. Write the name, = and a new value, without let this time. The old value is thrown away. You can also copy one box into another.
Some boxes should never change, like your birthday. Make those with , short for constant. Try to change one and the checker stops you with TS2588.
+ can strings, end to end. "I feel " + mood sticks two strings into one. Leave a space inside the quotes, or the words will bump into each other.
let mood: string = "sleepy";
mood = "happy";
const birthday: string = "4 May";
console.log("I feel " + mood);
console.log("My birthday is " + birthday); Use const for boxes that stay the same, and let for boxes you plan to change.
guess first
A copy, then a change. What is for lunch?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
let snack: string = "crisps";
let lunch: string = snack;
snack = "grapes";
console.log(lunch);
your turn
Your turn. Change your mind.
Type a drink in the first blank and a different drink in the second. Then press run and watch the box change.
fix it
You scored again, but this will not run. Fix it!
- Read the error:
TS2588: Cannot assign to 'score' because it is a constant. - A box made with
constcan never change. This score needs to go up. - Change
consttoleton line 1, then press run.
nailed it
your boxes can change now. :D
- Storing a new value replaces the old one.
constmakes a box that can never change.+joins strings, so mind the spaces.
new words in your collection
- const
- join
This lesson isn’t saved. A free account remembers every lesson you finish.