

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Objects
incomplete
2: No Colon
incomplete
3: Updating Properties
incomplete
4: Nesting Properties
incomplete
5: Nesting Properties Quiz
incomplete
6: Optional Chaining
incomplete
7: When to Chain
incomplete
8: Object Methods
incomplete
9: Methods Mutate
incomplete
10: Initializing Props
incomplete
11: Strings As Keys
incomplete
12: This
incomplete
13: Arrow Functions
incomplete
14: Fat Arrows and This
incomplete
15: Spread Syntax
incomplete
16: Return Objects
incomplete
17: Destructuring
incomplete
18: Not Bound
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
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