FAQ: Advanced Objects - Advanced Objects Introduction

This community-built FAQ covers the “Advanced Objects Introduction” exercise from the lesson “Advanced Objects”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Advanced Objects Introduction

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi, I have a question. The cheat sheet says that we are not allowed to start objects with symbols like - but the example has advanced objects. Then it says that we have to enclose them in ’ ’ because it has to be treated as a string. But I don’t see that being done here either.

Really confused.
Thanks!

true is a special boolean that does not require the quotes. JavaScript knows it as such and recognizes true or false as part of a global boolean value.
I hope this helps?

Hi so I have to admit I find the vocab difficult with coding so far. Because of this I am not sure how to google the right question. below is the first example in the beginning of the lesson. Why can I call the greeting using robot.greeting(); but I can not do it with and of the other items?

const robot = {
model: ‘B-4MI’,
mobile: true,
greeting() {
console.log(I'm model ${this.model}, how may I be of service?);
}
}
robot.greeting();

similarly in the next example it shows for shinyNewRobot, I could not call the mass produced greeting using the same syntax. The error is always “is not a function”.

const massProdRobot = (model, mobile) => {

return {
model,
mobile,
greeting() {
console.log(I'm model ${this.model}, how may I be of service?);
}
}
}

//how do I call this greeting

const shinyNewRobot = massProdRobot(‘TrayHax’, true)

//shinyNewRobot.greeting(); Error says .greeting is not a function

Hello! I tried running your code on repl.it and I got a lot of syntax errors. You don’t have back ticks around the strings you’re console.logging, and for some reason I had to replace the quotations on TrayHax and B-4MI. After correcting them the code was passing.

Otherwise, your code looks good. It should be passing it as you called it.

Hi I am so confused about the getter and setter in this first example. I tried playing with the code a bit to make sure I understood the basics before moving on and I got stuck with the setter.

//these 3 are totally ok! :slight_smile:
robot.greeting()
let robot2 = massProdRobot(‘skdfj’,false);
robot2.greeting();

//but then these 2 below give me an error ive never seen before and googling got me a rabit hole soo deep over my head I dont know even what question to ask.

chargingStation.newCapacity = 50

console.log(chargingStation.robotCapacity);

error repeats until the “console” is full.
/home/ccuser/workspace/advanced-objects-adv-intro/main.js:35
return this.robotCapacity;
^

RangeError: Maximum call stack size exceeded
at Object.get robotCapacity [as robotCapacity] (/home/ccuser/workspace/advanced-objects-adv-intro/main.js:35:16)

Take a closer look at this line. Because you’re using robotCapacity rather than _robotCapacity, this results in the endless calling of callback functions. This is because while _robotCapacity (with the underscore) is a variable, robotCapacity (without the underscore) is the name of the getter and setter functions.

1 Like