Meal maker: undefined


#1

Hey guys so I have finally gotten through this project, the generateRandomMeal() function works as it should but when I console log the the function it return undefined with no error. Can someone show me where I went wrong ? Your replies are appreciated.

This is what is being logged to the console: ‘Your total is 16.75, potato wedges, oxtails, vanilla cake
undefined’

Here’s a link to my code https://gist.github.com/c0d294f5eb79b982fe8376b39656b6b0


#2

Your setters do not look quite right. They are replacing the array with a value.


#3

I figured everything out thanks for the reply but I gotta ask what is the purpose of the getter and setters if we are not using the setters explicitly to set anything ? like so menu.RandomSetter = 23;


#4

With a plain object, the only way to modify a property is with a direct assignment, no logic or minimal logic involved. By giving properties their own getters and setters we expand their horizon to include functionality. A setter can introduce a range of criteria that any replacement value must adhere to, for instance. This would be one major reason for having a setter to oversee what values a property is replaced with, as opposed to permitting wholesale changes to a property.

const thermostat = {
  _roomTemp = 20,
  get roomTemp () {
    return this._roomTemp;
  },
  set roomTemp (newTemp) {
    if (isNaN(newTemp) { return false; }
    if (18 <= newTemp && newTemp <= 22) {
      this._roomTemp = newTemp;
    }
  }
};

#5

Ok I understand what your saying. What I was asking was what is the purpose of having the getters and setters within the meal maker project ?


#6

Please post a link to this exercise so we can review the lesson text and look at our own code. Thanks.


#7

Sure thing https://www.codecademy.com/courses/learn-javascript-objects/projects/meal-maker?course_redirect=introduction-to-javascript