Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1let name = prompt("Your name?"); | Aa is a string, so a + 5 joins text instead of adding. If the user types 3 the result is "35". Use Number(prompt(...)). | |
| 2let age = prompt("Your age?"); console.log(typeof age); | Bif (answer === null) { console.log("Cancelled"); } | |
| 3prompt() returns null when the user presses Cancel, so you can check for it | CShows a message box, waits for the user to type, and stores what they typed in the variable name | |
| 4Input is a string, so convert it with Number() before doing maths | Dlet n = Number(prompt("Pick a number")); | |
| 5prompt("Your name?"); console.log("Hi " + name); | EPrints string, because prompt() always returns text, even when the user types digits | |
| 6let a = prompt("First number?"); let total = a + 5; | FThe answer was never stored in a variable, so name does not exist. Use let name = prompt("Your name?"); |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
prompt("question") — Shows a message box, waits for the user to type, then returns what they typed as a string. Store it in a variable. Cancel returns null.let name = prompt("What is your name?");let name = prompt("Your name?");
console.log("Hi " + name);let age = prompt("Age?");
console.log(typeof age);let name = prompt("Your name?");
if (name === null) {
console.log("Cancelled");
}let num = Number(prompt("Enter a number:"));