Learn JavaScript: Objects Meal Maker .....error


#1

Hello
I have just started using The discussion forum for the first time and my query is:

I get the following error when I do the following in
Topic:Learn JavaScript: Objects
Meal Maker

I cannot rectify the error…if anybody can help me will be appreciated

mains: this._courses.mains,
^
SyntaxError: Unexpected token :

let menu =
{
  _courses :
  {
    _appetizers	: [],
    _mains		 	:	[],
    _desserts		:	[],
  
    get appetizers() {
    	return this._appetizers;
	  	},
    get mains() {
    	return this._mains;
	  	},
    get desserts() {
    	return this._desserts;
	  	},
    set appetizers(appetizerIn) {
			this._appetizers.push(appetizerIn);
  	  },
    set mains(mainIn) {
      this._mains.push(mainIn);
	    },
    set desserts(dessertIn) {
      this._desserts.push(dessertIn);
    	}
    
  },
  
  get courses() {
  	return 
    {
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.desserts
    },
  },

};

#2

step 5 of the instructions read:

Inside your menu object, create an empty getter method for the _courses property.

i don’t see the menu object?


#3

Could you please elaborate…thanks again


#4

Elaborate on what? The more specific you are, the better answer i can give, the happier you are

you forgot to create the menu object, check step 5 of the instructions


#5

let menu =
{
_courses :
{
_appetizers : [],
_mains : [],
_desserts : [],

get appetizers() {
	return this._appetizers;
  	},
get mains() {
	return this._mains;
  	},
get desserts() {
	return this._desserts;
  	},
set appetizers(appetizerIn) {
		this._appetizers.push(appetizerIn);
  },
set mains(mainIn) {
  this._mains.push(mainIn);
    },
set desserts(dessertIn) {
  this._desserts.push(dessertIn);
	}

},
get courses(){},

get courses() {
}
};


#6

Last line is done twice sorry mistake from my side


#7

Oops, sorry, i seem to have made a mistake

the problem is here:

return 
    {
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.desserts
    },

return and { can’t be on a separate line


#8

Thank you very much it works


#9

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