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 | |
|---|---|---|
| 1class Player { } | AA blueprint that can be reused to make many player objects | |
| 2const hero = new Player('Kai', 100); | Bclass Pet { constructor(name) { this.name = name; this.energy = 5; } eat() { this.energy++; } } | |
| 3Modelling a real-world thing: a pet has data (name, energy) and actions (eat) kept together in one object | CCreates one object from the Player blueprint with its own data | |
| 4Reusing a blueprint: one class makes many objects, so you do not rewrite the same code | DThe same code is copied for each kind of thing instead of reusing a blueprint. Put the behaviour in a class method so every object can use it. | |
| 5let petName = 'Rex'; let petEnergy = 5; let petName2 = 'Mia'; let petEnergy2 = 8; | ERelated data is stored in loose separate variables, so it is not kept together and gets messy as the program grows. Use a Pet class and make one object per pet. | |
| 6function feedPet(name, energy) { return energy + 1; } // copied again as feedDog, feedCat... | Fconst a = new Pet('Rex'); const b = new Pet('Mia'); |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
OOP — Object-oriented programming: building a program from objects that bundle related data with the code that uses it, modelling real things and reusing a blueprint.class Player {
constructor(name) { this.name = name; }
}const a = new Player("Ava");
const b = new Player("Liam");class Car {
constructor(speed) { this.speed = speed; }
}class Pet {
constructor(name) { this.name = name; }
}const ava = new Player("Ava");
ava.points = 0;
console.log(ava.points);