Can you interpolate multiple .this methods in the same string and is the example I provide correct syntax for this method?


#1
let restaurant = {
  _name: 'Italian Bistro',
  _seatingCapacity: 120,
  _hasDineInSpecial: true,
  _entrees: ['Penne alla Bolognese', 'Chicken Cacciatore', 'Linguine pesto'],

  set seatingCapacity(newCapacity) {
    if (typeof newCapacity === 'number') {
      this._seatingCapacity = newCapacity;
    } else {
      console.log(`Change ${newCapacity} to a number.`)
    }
  },

 get seatingCapacity() {
    console.log(`There are ${this._seatingCapacity} seats at ${this._name}.`);
    return this._seatingCapacity;
  }
}
${this._seatingCapacity} seats at Italian Bistro.` with ${this._name} );

Before the chorus comes out a singing, no this is not perfect syntax. I'm learning.

Here is the exercise:
getter


#2

note that knowing the answer to this will not help me pass the challenge…if I actually know the answer. I am trying to verify if my thinking is correct.


#3

Singing starts…

Those are not methods, but properties.

Yes, you can interpolate whatever you like, there is no limit.

Not sure what this line is about…

Did you mean,

console.log(`${this._seatingCapacity} seats at Italian Bistro. with ${this._name}`);

Not sure I follow what this getter is supposed to be doing. Why is it logging?


#4

I figured it out and got it correct on my own :grin:


#5

Yeah, belay that last question. I see the author used it in his example.


#6

The getter was gonna get the seating capacity and then get the italian bistro instead of just using a string to say italian bistro. No pressure cause I figured it out on my own haha. (a different question obviously but the same exercise).


#7

what do you mean belay?


#8

It’s an old communication phrase,

Belay, belay!

which is piped when one wants the previous message to be ignored.


#9

I finished all the checkmarks for the exercise, but when I console.logged it I got the response: invalid response.

Yet, I still got the checkmark.
Is that a bug in the system?


#10
let person = {
  _name: 'Lu Xun',
  _age: 137,
  
  set age(ageIn) {
    if (typeof ageIn === 'number') {
      this._age = ageIn;
    }
    else {
      console.log('Invalid input');
      return 'Invalid input';
    }
  },
  get age () {console.log(`${this.name}` + ' is' + `${this.age}` + ' years old.' )}

};

person.age = 'Thirty-nine';
person.age = 39;
console.log(person.age)

Like I said, I already passed the challenge. Was just curious about what’s going on.


#11

Setters don’t normally return anything since they are internal.


#12

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.