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 total(scores) { let sum = 0; for (const s of scores) sum += s; return sum; } | AEmpty square brackets after the parameter name are invalid syntax. The array should be used by name or an index. | |
| 2function addBonus(scores) { scores.push(10); } | BThe function receives an array in its parameter and loops over it to add up every item. | |
| 3Call a function and give it an array as the argument | CThe function changes the original array that was passed in by adding an item to it. | |
| 4A function returns a new array and leaves the original array unchanged | Dtotal([4, 7, 9]); | |
| 5function total(scores) { let sum = 0; for (const s of scores) sum += s; } | EThere is no return statement, so the function gives back undefined instead of the total. | |
| 6function largest(scores) { return Math.max(scores[]); } | Ffunction doubleAll(nums) { return nums.map(n => n * 2); } |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
function total(scores) — A function with a parameter that receives an array when called, e.g. total([4, 7, 9]). The function can loop over it, return a new array, or change the original array.function count(list) {
return list.length;
}function double(nums) {
return nums.map(n => n * 2);
}function addItem(list, item) {
list.push(item);
}const scores = [4, 7, 9];
addItem(scores, 5);
console.log(scores);function show(names) {
for (const n of names) console.log(n);
}