diff --git a/index.js b/index.js index 833600e1..0b2bdd97 100644 --- a/index.js +++ b/index.js @@ -15,11 +15,11 @@ The function should: Example createMenuItem('tacos', 8, 'Lunch') should return {name: 'tacos', price: 8, category: 'Lunch'} */ - -function createMenuItem(/*Your code here*/){ - /*Your code here*/ +function createMenuItem(name, price, category){ + const lunchTacos = {name , price, category}; + return lunchTacos; } - +// console.log("Task 1a:", createMenuItem('tacos', 8, 'Lunch')) /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 1b (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -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("Task 1b:", createMenuItem('lunchPizza', "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,9 +50,16 @@ const burger = { name: "Burger", price: 18, category: "Lunch", - + discount: function (string) { + if (string === 'teacher' || string === 'student') { + return this.price - (this.price * 0.25); + } else { + return this.price - (this.price * 0.10) + } + } } - +// console.log("Task 2:", burger.discount("teacher")); +// console.log("Task 2:", burger.discount("public")); ///////////////Reviews (MVP)/////////////////// @@ -72,7 +78,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): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -81,7 +87,8 @@ 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[reviews.length - 1]['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. @@ -95,11 +102,12 @@ 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}) + return array; } - - +// console.log("Task 5:", addReview(reviews, 'Billy', 2, 'Lame food!')) +// console.log(reviews); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 6: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Write a function to return a review based on the index of the review in the array. @@ -112,10 +120,10 @@ Use the getReviewByIndex function below to do the following: */ -function getReviewByIndex(/*Your code here*/) { - /*Your code here*/ +function getReviewByIndex(arr, num) { + return `${arr[num].name} gave the restaurant a ${arr[num].rating} star review, and their feedback was: ${arr[num].feedback}` } - +// console.log("Task 6:", getReviewByIndex(reviews, 0)) /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 7: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -131,10 +139,10 @@ Use the getLastReview function below to do the following: */ -function getLastReview(/*Your code here*/) { - /*Your code here*/ +function getLastReview(arr) { + return String(`${arr[arr.length-1].name} gave the restaurant a ${arr[arr.length-1].rating} star review, and their feedback was: ${arr[arr.length-1].feedback}`) } - +// console.log("Task 7:", getLastReview(reviews)); ///////////////πŸ”β˜•οΈπŸ½ STRETCHπŸ”β˜•οΈπŸ½//////////////////// @@ -152,11 +160,25 @@ Use the getReviewsByRating function below to do the following: {name:"Lauren", rating: 4, feedback: "Absolutely love that they have karaoke Fridays! Food and drink selection is okay."} ] */ - - function getReviewByRating(/* code here */) { - /* code here */ +const reviewRating = []; +function getReviewByRating(arr, num) { + for (let i = 0; i < arr.length; i++ ) { + if (arr[i].rating >= num && arr[i].rating < num + 1) { + reviewRating.push(arr[i]); + } + } + return reviewRating; } - +// console.log("Stretch 1:", getReviewByRating(reviews, 4)); + +//or useing filter +// function getReviewByRating(arr, num) { +// const reviewRating = arr.filter((item) => { +// return item.rating >= num && item.rating < num + 1; +// }) +// return reviewRating; +// } +// console.log("Stretch 1:", getReviewByRating(reviews, 4)); /* πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ STRETCH 2: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ Use the getLongReviews function below to do the following: @@ -171,10 +193,25 @@ Use the getLongReviews function below to do the following: ] */ -function getLongReviews(/* code here */) { - /* code here */ +// function getLongReviews(arr) { +// const longReviews = arr.filter((item) => { +// return item.feedback.length >= 15; +// }) +// return longReviews; +// } +// console.log("Stretch 2:", getLongReviews(reviews)); + +//using for loop +let longReviews = []; +function getLongReviews(arr) { + for (let i = 0; i < arr.length; i++) { + if (arr[i].feedback.length >= 15) { + longReviews.push({name: arr[i].name, rating: arr[i].rating, feedback: arr[i].feedback}) + } } - + return longReviews; +} +// console.log("Stretch 2:", getLongReviews(reviews)); /* πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ STRETCH 3: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ This stretch goal does not use the reviews data! You create your own object in this stretch goal. @@ -193,6 +230,7 @@ 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 */ +// ****Help***** function carMaker(/* code here */) { /* code here */ diff --git a/package-lock.json b/package-lock.json index 48103f21..389412cf 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", @@ -6910,10 +6910,13 @@ } }, "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", + "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/ms": { "version": "2.1.2", @@ -13680,9 +13683,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz", + "integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==", "dev": true }, "ms": {