-
-
Save codecademydev/abb2dbd65ccdcd363d583396aa255dcb to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const menu = { | |
_courses: { | |
_appetizers: [], | |
_mains: [], | |
_desserts: [], | |
}, | |
set appetizers(appetizer) { | |
if (typeof appetizer === 'string') { | |
this._appetizers.push(appetizer); | |
console.log(`You just added ${appetizer} to the list of appetizers.`); | |
} else { | |
console.log(`Please type the name of the appetizer.`) | |
} | |
}, | |
set mains(main) { | |
if (typeof main === 'string') { | |
this._mains.push(main); | |
console.log(`You just added ${main} to the list of main meals.`); | |
} else { | |
console.log(`Please type the name of the meal.`) | |
} | |
}, | |
set desserts(dessert) { | |
if (typeof dessert === 'string') { | |
this._desserts.push(dessert); | |
console.log(`You just added ${dessert} to the list of desserts.`); | |
} else { | |
console.log(`Please type the name of the dessert.`) | |
} | |
}, | |
get appetizers() { | |
return `Here are the appetizers on the menu: ${this._appetizers}`; | |
}, | |
get desserts() { | |
return `Here are the main meals on the menu: ${this._desserts}`; | |
}, | |
get mains() { | |
return `Here are the appetizers on the menu: ${this._mains}`; | |
}, | |
get courses () { | |
return { | |
appetizers: this._courses.appetizers, | |
mains: this._courses.mains, | |
desserts: this._courses.desserts | |
} | |
}, | |
addDishToCourse (courseName, dishName, dishPrice) { | |
const dish = { | |
name: dishName, | |
price: dishPrice | |
}; | |
this._courses[courseName].push(dish); | |
}, | |
getRandomDishFromCourse: (courseName) => { | |
const dishes = this._courses[courseName]; | |
const randomIndex = Math.floor(Math.random() * dishes.length); | |
return dishes[randomIndex]; | |
}, | |
generateRandomMeal () { | |
const appetizer = this.getRandomDishFromCourse("appetizers"); | |
const main = this.getRandomDishFromCourse("mains"); | |
const dessert = this.getRandomDishFromCourse("desserts"); | |
const totalPrice = appetizer.price + main.price + dessert.price; | |
return `Your meal is ${appetizer.name}, ${main.name}, ${dessert.name}. Your total is $${totalPrice}.` | |
} | |
}; | |
// menu.desserts = 'rice pudding'; | |
menu.addDishToCourse("appetizers", "basmati rice with steamed vegetables", 6.50); | |
menu.addDishToCourse("appetizers", "chicken tikka", 3.00); | |
menu.addDishToCourse("appetizers", "yogurt with honey", 5.00); | |
menu.addDishToCourse("mains", "dal makhany", 12.00); | |
menu.addDishToCourse("mains", "red curry soup", 9.00); | |
menu.addDishToCourse("mains", "yellow curry with sweet potato", 12.00); | |
menu.addDishToCourse("desserts", "rice pudding", 3.00); | |
menu.addDishToCourse("desserts", "dates with cherries", 3.00); | |
console.log(menu.courses); | |
console.log(menu.generateRandomMeal()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment