Methods can change the properties of their objects as well:
const tree = {
height: 256,
color: "green",
cut() {
this.height /= 2;
},
};
tree.cut();
console.log(tree.height);
// prints 128
tree.cut();
console.log(tree.height);
// prints 64
You might be wondering:
Wait... I thought
treewas a constant?!?
You're right, but in JavaScript, the const keyword doesn't stop you from changing the properties of an object... it only stops you from reassigning the variable (tree in this case) to a new object. Do not trust const objects to have constant contents!
Complete the sendMessage() method on the campaign object. For now, it should simply increment the campaign's sentMessages counter by 1.