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 | |
|---|---|---|
| 1deposit(amount) { this.balance += amount; return this.balance; } | Adescribe() { return `${this.name} has $${this.balance}`; } | |
| 2getArea() { return this.width * this.height; } | BThe properties are missing this. so the method looks for a variable called balance instead of the object's property. It should be this.balance. | |
| 3A method can take a parameter and use it with a property to work out a value to return. | CThe method never uses return, so the calculated area is thrown away and the caller gets undefined. It should be return this.width * this.height; | |
| 4A method can return a string built with a template literal using the object's properties. | DA method with no parameters that returns a number worked out from the object's width and height properties. | |
| 5deposit(amount) { balance += amount; return balance; } | EA method that takes an amount, adds it to the object's balance and returns the new balance. | |
| 6getArea() { this.width * this.height; } | FaddBonus(extra) { return this.points + extra; } |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
${this.name} has ${this.balance} points; }deposit(amount) { this.balance += amount; return this.balance; } — A class method takes a parameter (amount) and uses return to give back a value worked out from the object's properties, such as the new balance.deposit(amount) {
this.balance += amount;
return this.balance; }deposit(amount) {
this.balance += amount;
return this.balance; }getArea() {
return this.width * this.height;
}getInfo() {
return `${this.name} has ${this.points}`;
}const acc = new Account("Sam", 50);
const newBal = acc.deposit(20);
console.log(newBal);