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 | |
|---|---|---|
| 1this.balance += amount; | AThe + operator only works out a total and throws it away. It never stores the result, so this.balance does not change. | |
| 2if (amount > 0) { this.balance += amount; } | Bacc.deposit(50); acc.deposit(50); // balance is now 100 if it started at 0 | |
| 3A method changes the object's state by updating a property with this | CAdds the amount to the object's own balance property, so the object's state changes | |
| 4Calling a changing method twice applies the change twice, so the state builds up | DChecks the amount is valid before changing the property, so bad values leave the state unchanged | |
| 5deposit(amount) { balance += amount; } | Edeposit(amount) { this.balance += amount; } | |
| 6deposit(amount) { this.balance + amount; } | Fbalance has no this. in front of it, so the method does not update the object's property. It looks for a plain variable and causes an error. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
this.balance += amount — A method line that updates the object's own property, so its state changes each time the method is called. Calling deposit(50) twice adds 50 twice.deposit(amount) {
this.balance += amount;
}if (amount <= this.balance) {
this.balance -= amount;
}withdraw(amount) {
this.balance -= amount;
}account.deposit(50);
account.deposit(50);
console.log(account.balance);if (amount > 0) {
this.balance += amount;
}