×

typescript · level 1 · unit 3 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A fills in the gaps in your text.

Wrap text in backticks instead of quotes and you get a template literal. The backtick key is often at the top left, under Esc. Inside, ${name} is swapped for the value in the box.

prompt always gives back text, even when someone types digits. To it, use Number(). Number("12") gives the number 12, and String() turns a number back into text.

Text that is not a number, like Number("cake"), gives , short for Not a Number. And Number(null) gives 0, so Number(prompt("Age?")) is safe when nobody answers.

let name: string = "Sam";
let age: number = 9;
console.log(`Happy birthday, ${name}! You are ${age}.`);
console.log(`Next year you will be ${age + 1}.`);
console.log("Candles: " + String(age));

Number() only works on text that looks like a number. Anything else becomes NaN.