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 dog = { speak() { console.log('Woof!'); } }; | Aconst player = { jump() { return 'Up!'; } }; | |
| 2dog.speak(); | BCalls the speak method on the dog object | |
| 3A method is a function stored as a property of an object, so it is written inside the object's curly braces | CCreates an object literal with a method called speak stored inside it | |
| 4A plain function is called by its name alone, but a method must be called with the object name, a dot and brackets | DThe brackets are missing, so the method is not called. It only refers to the function and nothing runs. Fix: cat.meow(); | |
| 5const cat = { meow() { console.log('Meow'); } }; cat.meow; | Eplayer.jump(); | |
| 6const cat = { meow() { console.log('Meow'); } }; meow(); | FThe method is called like a plain function. It belongs to cat, so it needs the dot: cat.meow(); |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
greet() { ... } — A method is a function stored as an object property. Write it inside the object, then call it with a dot and brackets: person.greet().const pet = { speak() { return "Woof"; } };
console.log(pet.speak());const pet = { speak() { return "Woof"; } };
console.log(pet.speak());const user = { name: "Mia",
hello() { return "Hi " + this.name; }
};const maths = {
triple(n) { return n * 3; }
};const calc = { double(n) { return n * 2; } };
console.log(calc.double(4));