javascript · level 1 · unit 2 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
lets your program ask a question.
prompt is like a waiter taking your order. It asks a question, waits while the person types an answer, then hands back what they typed as a string.
Store the answer in a variable so you can use it. let snack = prompt("Favourite snack?"); puts whatever they type into the box called snack.
prompt does not add anything to the output. Only console.log does that, so show the answer with console.log when you want to see it.
The answer is always a string, even when someone types a number.
guess first
The answer typed in is crisps. What will this show?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
let snack = prompt("Favourite snack?");
console.log("Yum, " + snack);
your turn
Your turn. Use both answers.
The answers Ada and pizza are typed in for you. Fill each blank with a box name, so the sentence uses both answers, then press run.
fix it
The answer went nowhere. Can you fix it?
- It is a ReferenceError: JavaScript has never heard of petName. Where should that box be made?
prompthands back the answer, but nothing catches it. Store it in a box withlet.- Start line 1 with let petName = so the answer goes into the box, then press run.
nailed it
your program can ask questions now. :D
promptasks a question and hands back the answer.- Store the answer in a variable to use it.
- The answer is always a string.
new words in your collection
- prompt
This lesson isn’t saved. A free account remembers every lesson you finish.