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 | |
|---|---|---|
| 1const team = [new Player('Ava', 12), new Player('Leo', 9)]; | AUses = (assignment) instead of === (comparison), so the search changes the data and finds the wrong object | |
| 2function totalPoints(players) { return players.reduce((sum, p) => sum + p.points, 0); } | BThe helper never adds the points or returns a value, so it gives back undefined instead of a total | |
| 3A main function runs the steps by calling small helper functions in order | CCreates an array that holds many objects made from the Player class | |
| 4A class holds the data for each object, so one blueprint makes many objects | Dfunction main() { const total = totalPoints(team); console.log(total); } | |
| 5function findPlayer(players, name) { return players.find(p => p.name = name); } | EA helper function that does one job: it adds up the points of every object in the array | |
| 6function totalPoints(players) { players.forEach(p => p.points); } | Fclass Player { constructor(name, points) { this.name = name; this.points = points; } } |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
modular program — A program built from small parts: a class for the data, an array of its objects, and helper functions that each do one job (like totals or searches), all run by a main function.class Student {
constructor(name, mark) {
this.name = name;const students = [];
students.push(new Student("Ava", 88));function findStudent(list, name) {
return list.find(s => s.name === name);
}function main() {
console.log(totalMarks(students));
}const test = [new Student("Zoe", 50)];
console.assert(totalMarks(test) === 50);