As previous Rock, Paper, or Scissors task it uses yarn and jest testing framework so the process is the same:
git clonethe repo.- Create new
branchwith your name and checkout. - Run
yarn. - To run tests: run
yarn testoryarn watchdepending 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
_coursesproperty 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
_coursesobject calledappetizers,mains, anddesserts. Each one of these should initialize to an empty array. -
Inside your
menuobject, create a getter method for the_coursesproperty. It should return an object that contains key/value pairs forappetizers,mains, anddesserts. -
Inside the
menuobject, 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_coursesobject based on whatcourseNamewas 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
menuobject called.getRandomDishFromCourse(). It will take in one parameter which is thecourseName. As you may already assumed:- It should get all dishes from appropriate
courseNameinside_coursesproperty - 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
appetizervariable which should be the result of calling the.getRandomDishFromCourse()method when we pass in anappetizersstring to it. - Create a
mainvariable anddessertvariable the same way you created theappetizervariable, 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
menuby adding someappetizers,mains, anddessertswith the.addDishToCourse()function.Inside
index.jsadd 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 yourmealvariable to see what meal was generated for you. You can do so by runningnode index.jsin the terminal.