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 | |
|---|---|---|
| 1function add(a, b) { return a + b; } | AThe function logs the value instead of returning it, so result is undefined. Use return n * 2; instead. | |
| 2function add(a, b) { console.log(a + b); } | Bfunction showScore(score) { console.log(score); } | |
| 3To save a function's answer in a variable, the function must return the value. | Clet total = add(2, 3); // add uses return | |
| 4If you only want to display a message for the user to read, console.log is enough. | DHands the sum back to the caller, so it can be stored in a variable or used in other code. | |
| 5function double(n) { console.log(n * 2); } let result = double(4); console.log(result); // undefined | EOnly shows the sum in the console. The function gives back undefined, so there is nothing to store. | |
| 6function square(n) { return n * n; } square(5); | FThe returned value is never used. Store it with let answer = square(5); or show it with console.log(square(5)). |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
return — Hands a value back to the code that called the function so it can be stored or used. console.log only shows a value in the console, so a function that only logs gives back undefined.function double(n) {
return n * 2;
}function square(n) { return n * n; }
let result = square(4);
console.log(result);function show(n) { console.log(n * 2); }
let x = show(5);
console.log(x); // undefinedfunction add(a, b) { return a + b; }
let sum = add(2, 3);
console.log(sum);function getAge() { return 13; }
let age = getAge() + 1;
console.log(age);