JavaScript objects can have methods, just like classes in Python or structs in Go. Objects are interesting in JavaScript because they play the role of dictionaries and classes in other languages (Yes, JS also has classes, but we'll get to them later).
Methods are functions that are defined on an object. They can access and change the properties of the object in question. In the context of an object method, the this keyword refers to the object itself, like self in Python (we'll talk about the admittedly hairy this keyword in more detail later).
const person = {
firstName: "Lane",
lastName: "Wagner",
getFullName() {
return this.firstName + " " + this.lastName;
},
};
console.log(person.getFullName());
// Lane Wagner
Complete the getRemainingMessages() method in the campaign object. The method should calculate and return the number of remaining messages a user can send in the campaign. The calculation is based on the following formula:
remainingMessages = maxMessages - sentMessages