We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Methods Mutate

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 tree was 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!

Assignment

Complete the sendMessage() method on the campaign object. For now, it should simply increment the campaign's sentMessages counter by 1.