×

javascript · 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.

Write a string between backticks, the slanted quote marks, and you get a template literal. Anything inside ${} is swapped for its value, like filling in the gaps on a birthday card.

Remember, prompt always gives back text. To do maths with it, it first. Number("12") turns the text "12" into the number 12.

You can wrap one inside the other. Number(prompt("How old are you?")) asks the question and converts the answer in one go.

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

On most UK keyboards, the backtick key sits to the left of the 1 key.