diff --git a/index.js b/index.js index 833600e1..0dbdbc6d 100644 --- a/index.js +++ b/index.js @@ -16,10 +16,11 @@ The function should: */ -function createMenuItem(/*Your code here*/){ - /*Your code here*/ -} +function createMenuItem(name, price, category){ + return {name, price, category}; +} +console.log(`task 1a:`, createMenuItem(`tacos`, 8, `Lunch`)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 1b (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -31,8 +32,9 @@ Test your createMenuItems function by doing the following: For example: createMenuItem("pizza",5,"lunch") would return this as the object: {name:"Pizza",price:5,category:"lunch"} */ - - +console.log(`task 1b:`, createMenuItem(`pizza`, 5, `Lunch`)); +console.log(`task 1b:`, createMenuItem(`waffles`, 10, `Brunch`)); +console.log(`task 1b:`, createMenuItem(`chocolate milkshake`, 6, `Drinks`)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 2: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ You're having a lunch special! 25% off for teachers and students, 10% off for everyone else. Add a method to the burger object below that automatically calculates price depending on the string received as a parameter. @@ -50,11 +52,17 @@ Using the burger object below do the following: const burger = { name: "Burger", price: 18, - category: "Lunch", - + category: "Lunch", + discount: function(person){ + if(person === `teacher` || person === `student`){ + return this.price - (this.price * 0.25); + }else if(person ===`public`){ + return this.price - (this.price * 0.10); + } + } } - +console.log(`task 2:`, burger.discount(`teacher`)); ///////////////Reviews (MVP)/////////////////// const reviews = [ @@ -73,7 +81,7 @@ Using the reviews array above: 1. log only Julius' feedback to the console - no function needed */ - +console.log(`task 3:`, reviews [5].feedback); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 4 (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Reyna's feedback is missing! Use what you know to do the following: (no function needed) @@ -81,7 +89,9 @@ Reyna's feedback is missing! Use what you know to do the following: (no function 2. log the reviews array to the console to check your work */ +reviews[7].feedback = `this place is chill with really cool people, great for getting work done on weekdays`; +console.log(`task 4:`, reviews); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 5: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Write a function that creates an object with name, rating, feedback, add the new review to the end of an array and returns the resulting array. @@ -93,12 +103,11 @@ Use the addReview function below to do the following: 🌟 EXAMPLE: addReview(reviews, 'Billy', 2, 'Lame food!') should add the following to the end of the array: {name: 'Billy', rating: 2, feedback: 'Lame food!'} 4. Return the updated array */ - - -function addReview(/*Your Code Here */){ - /*Your Code Here */ +function addReview(reviews, name, rating, feedback){ + reviews.push({name, rating, feedback}); + return reviews; } - +console.log(addReview(reviews, `Billy`, 2, `Lame food!`)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 6: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -112,11 +121,11 @@ Use the getReviewByIndex function below to do the following: */ -function getReviewByIndex(/*Your code here*/) { - /*Your code here*/ +function getReviewByIndex(array, number) { + return `${array[number].name} gave the restaurant a ${array[number].rating} star review, and their feedback was: ${array[number].feedback}`; } - +console.log(`task 6:`, getReviewByIndex(reviews, 4)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 7: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Write a function to get information about the most recent (last) review called `getLastReview` @@ -131,11 +140,11 @@ Use the getLastReview function below to do the following: */ -function getLastReview(/*Your code here*/) { - /*Your code here*/ -} - +function getLastReview(array) { + return `${array[array.length -1].name} gave the restaurant a ${array[array.length -1].rating} star review, and their feedback was: ${array[array.length -1].feedback}`; +} +console.log(`task 7:`, getLastReview(reviews)); ///////////////πŸ”β˜•οΈπŸ½ STRETCHπŸ”β˜•οΈπŸ½//////////////////// @@ -153,9 +162,7 @@ Use the getReviewsByRating function below to do the following: ] */ - function getReviewByRating(/* code here */) { - /* code here */ - } + /* πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ STRETCH 2: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ diff --git a/package-lock.json b/package-lock.json index 48103f21..0f48f45e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "devDependencies": { "@babel/core": "7.17.5", "@babel/plugin-transform-runtime": "7.17.0",