As previous Rock, Paper, or Scissors task it uses yarn
and jest
testing framework so the process is the same:
git clone
the repo.- Create new
branch
with your name and checkout. - Run
yarn
. - To run tests: run
yarn test
oryarn watch
depending on your preference.
As a frequent diner, you love trying out new restaurants and experimenting with different foods. However, having to figure out what you want to order can be a time-consuming ordeal if the menu is big, and you want an easier way to be able to figure out what you are going to eat.
In this project, you should use JavaScript objects and iterators to randomly create a three-course meal based on what is available on a menu. We’ll keep running it until we’re satisfied with the generated meal!
-
Add a
_courses
property to the menu object (inmenu.js
) and set its value to an empty object. This property will ultimately contain a mapping between each course and the dishes available to order in that course. -
Create three properties inside the
_courses
object calledappetizers
,mains
, anddesserts
. Each one of these should initialize to an empty array. -
Inside your
menu
object, create a getter method for the_courses
property. It should return an object that contains key/value pairs forappetizers
,mains
, anddesserts
. -
Inside the
menu
object, we are going to create a method called.addDishToCourse()
which will be used to add a new dish to the specified course on the menu.The method should take in three parameters: the
courseName
, thedishName
, and thedishPrice
. -
The
.addDishToCourse()
method should create an object called dish which has a name and price which it gets from the parameters.The method should then push this dish object into the appropriate array in your
menu
‘s_courses
object based on whatcourseName
was passed in. -
Now, we’re going to need another function which will allow us to get a random dish from a course on the menu, which will be necessary for generating a random meal.
Create a method inside the
menu
object called.getRandomDishFromCourse()
. It will take in one parameter which is thecourseName
. As you may already assumed:- It should get all dishes from appropriate
courseName
inside_courses
property - Randomly pick one of them
- Return it.
- It should get all dishes from appropriate
-
Now that we have a way to get a random dish from a course, we can create a
.generateRandomMeal()
function which will automatically generate a three-course meal for us. The function doesn’t need to take any parameters.- The function should create an
appetizer
variable which should be the result of calling the.getRandomDishFromCourse()
method when we pass in anappetizers
string to it. - Create a
main
variable anddessert
variable the same way you created theappetizer
variable, but make sure to pass in the right course type. - Calculates the total price and returns a string that contains the name of each of the dishes and the total price of the meal, formatted the following way:
{ dishes: ["APPETIZER_NAME", "MAIN_NAME", "DESSERT_NAME"], total: "$TOTAL_PRICE" }
- The function should create an
-
Now that we’ve finished our menu, object, let’s use it to create a
menu
by adding someappetizers
,mains
, anddesserts
with the.addDishToCourse()
function.Inside
index.js
add at least 3 dishes to each course (or more if you like!). -
Once your menu has items inside it, generate a meal by using the
.generateRandomMeal()
function on your menu, and save it to a variable calledmeal
. Lastly, print out yourmeal
variable to see what meal was generated for you. You can do so by runningnode index.js
in the terminal.