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 | |
|---|---|---|
| 1// Prediction: prints 10 | AChanging many things at once makes it hard to tell which change caused a bug. Change one thing at a time and re-test. | |
| 2function area(w, h = 1) { | Bfunction greet(name, greeting) { | |
| 3After each small change, re-run your tests to check nothing else broke | CPredict the output first by reading the code, before you run it or change anything | |
| 4Add a new parameter to an existing function so it can do more | Dconsole.assert(area(2, 3) === 6); | |
| 5// Changed 5 functions at once, then ran it | EAdds a parameter to an existing function, with a default so old calls still work | |
| 6function total(a, b, c) { return a + b; } total(1, 2); | FA parameter was added but the existing call was not updated, so c is undefined. Update the calls or give c a default and re-run the tests. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
modify code — Read the code and predict its output, change one small part at a time, then re-run your tests after each change to check that nothing else broke.function greet(name, greeting) {
return greeting + ", " + name;
}function double(n) { return n * 2; }
console.assert(double(4) === 8, "failed");// area = width times height
function area(w, h) { return w * h; }
console.log(area(3, 4)); // 12// old calls total(5) must still give 5
function total(price, qty = 1) {
return price * qty; }// fix: 18 counts as an adult
function isAdult(age) { return age >= 18; }
console.assert(isAdult(18) === true);