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 | |
|---|---|---|
| 1return square(a) + square(b); | AThe function calls the helper square() twice and adds the results, so square() does the squaring and this function only combines them. | |
| 2function main() { getInput(); process(); showResult(); } | Bfunction main() { readScores(); average(); report(); } | |
| 3A helper function does one small job, and a larger function calls it to get that job done. | CA main function that calls each step function in order, one per box of the decomposition. | |
| 4Each box of a decomposition becomes its own function, and a main function calls them in order. | DThe helper is not called. Writing square without brackets just refers to the function and does not run it, so no result is shown. It should be square(3). | |
| 5function hypotenuse(a, b) { return Math.sqrt(square(a) + square(b)) } function square(n) { return n * n } console.log(square); | Efunction area(w, h) { return multiply(w, h); } | |
| 6function main() { showResult(); calculate(); getInput(); } | FThe step functions are called in the wrong order. Input must come first, then the calculation, then showing the result. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
return square(a) + square(b); — A function can call another function inside its body. Here square() is a helper, so the bigger function stays short and each function does one job.const square = n => n * n;
const cube = n => n * square(n);function setup() { console.log("Ready"); }
function main() { setup(); }
main();const isEven = n => n % 2 === 0;
const check = n => isEven(n) ? "yes" : "no";const area = (w, h) => w * h;
const cost = (w, h, r) => area(w, h) * r;const sum = (a, b) => a + b;
const mean = (a, b) => sum(a, b) / 2;