diff --git a/index.js b/index.js index 26cec7a5..6d4af7f6 100644 --- a/index.js +++ b/index.js @@ -16,11 +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): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Invoke your function! @@ -52,8 +52,17 @@ const burger = { price: 18, 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); + }else{ + return 'no discount available' + } + } } - +console.log('task 2', burger.discount("teacher")) ///////////////Reviews (MVP)/////////////////// @@ -72,8 +81,7 @@ const reviews = [ 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) @@ -95,10 +103,21 @@ Use the addReview function below to do the following: */ -function addReview(/*Your Code Here */){ - /*Your Code Here */ +function addReview(array, name, rating, feedback){ + + array.push({name, rating, feedback}); + + /*{ + name: Daniela + rating: 5 + feedback: 'Beautiful atmosphere and wonderful vegan options!' + };*/ + + return array; + } +console.log(addReview(reviews, 'Daniela', 5, 'Beautiful atmosphere and wonderful vegan options!')); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 6: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -112,10 +131,10 @@ 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(getReviewByIndex(reviews, 0)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 7: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -131,10 +150,10 @@ 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(getLastReview(reviews)); ///////////////πŸ”β˜•οΈπŸ½ STRETCHπŸ”β˜•οΈπŸ½//////////////////// 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",