diff --git a/index.js b/index.js index 833600e1..1c8ddb77 100644 --- a/index.js +++ b/index.js @@ -16,8 +16,8 @@ The function should: */ -function createMenuItem(/*Your code here*/){ - /*Your code here*/ +function createMenuItem(name, price, category){ + return {name: name, price: price, category: category}; } @@ -31,8 +31,7 @@ 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(createMenuItem("pizza",5,"lunch")); /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 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. @@ -51,8 +50,17 @@ const burger = { name: "Burger", price: 18, category: "Lunch", - + discount: function (arg) { + if (arg === "teacher" || arg === "student") { + this.price = 18 - (18 * .25); + } else { + this.price = 18 - (18 * .10); + } + return this.price; + } } +console.log(burger.discount("teacher")); +console.log(burger.discount("public")); @@ -72,6 +80,7 @@ const reviews = [ Using the reviews array above: 1. log only Julius' feedback to the console - no function needed */ +console.log(reviews[5].feedback); @@ -80,7 +89,8 @@ Reyna's feedback is missing! Use what you know to do the following: (no function 1. Add this feedback to Reyna's rating - "this place is chill with really cool people, great for getting work done on weekdays" 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(reviews[7].feedback); /* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 5: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 @@ -95,8 +105,9 @@ 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: name, rating: rating, feedback: feedback}); + return array; } @@ -112,8 +123,8 @@ Use the getReviewByIndex function below to do the following: */ -function getReviewByIndex(/*Your code here*/) { - /*Your code here*/ +function getReviewByIndex(array, index) { + return `${array[index].name} gave the restaurant a ${array[index].rating} star review, and their feedback was: ${array[index].feedback}`; } @@ -131,8 +142,8 @@ 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}` } @@ -153,9 +164,18 @@ Use the getReviewsByRating function below to do the following: ] */ - function getReviewByRating(/* code here */) { - /* code here */ + function getReviewByRating(array, rating) { + const newArray =[]; + for (let i = 0; i < array.length; i++) + { + if (Math.floor(array[i].rating) === Math.floor(rating)) + { + newArray.push(array[i]); + } + } + return newArray; } + console.log(getReviewByRating(reviews, 4)); /* 💪💪💪💪💪💪💪💪💪💪 STRETCH 2: 💪💪💪💪💪💪💪💪💪💪 @@ -171,9 +191,19 @@ Use the getLongReviews function below to do the following: ] */ -function getLongReviews(/* code here */) { - /* code here */ +function getLongReviews(array) { + const longReviews = []; + for (let i = 0; i < array.length; i++) + { + if (array[i].feedback.split(" ").length > 15) + { + longReviews.push(array[i]); + } + } + return longReviews; } + +console.log(getLongReviews(reviews)); /* 💪💪💪💪💪💪💪💪💪💪 STRETCH 3: 💪💪💪💪💪💪💪💪💪💪 @@ -193,13 +223,6 @@ Use the carMaker function below to do the following: It would return 110 because it was created with 10 as the odometer and we added 100 to it with the drive method */ - -function carMaker(/* code here */) { - /* code here */ - -} - - /* 🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑 */ function foo(){ console.log('its working'); 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",