Hi, I have a question. The cheat sheet says that we are not allowed to start objects with symbols like - but the example has . 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.
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?);
}
}
}
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!
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.