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 isEven(n) { return n % 2 === 0; } | AA separate test that calls one function with a known input and compares the output with the expected answer. | |
| 2console.log(double(4)); // expect 8 | BThe function has no return statement, so it gives back undefined and the main section prints undefined instead of 8. | |
| 3The main section is short. It calls the functions and lets them do the work. | CA small function that takes a parameter n and returns true or false so the main section can use it in an if statement. | |
| 4A comment above a function explains what the function does, what it takes in and what it returns. | D// Returns the area of a rectangle function area(w, h) { return w * h; } | |
| 5function double(n) { n * 2; } console.log(double(4)); | EThe function is never called because the brackets and the argument are missing, so result holds the function and not the answer. | |
| 6function double(n) { return n * 2; } let result = double; | Flet total = addUp(5); console.log(total); |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
function double(n) { return n * 2; } — Build a program from small functions that take parameters and return values, then call them from a short main section. Add a comment above each function and test each one separately.function double(n) { return n * 2; }// Doubles a number
function double(n) { return n * 2; }function double(n) { return n * 2; }
let result = double(5);
console.log(result);function isEven(n) { return n % 2 === 0; }
console.log(isEven(4));function double(n) { return n * 2; }
for (let i = 1; i <= 3; i++) {
console.log(double(i)); }