From a14a41f6498fa3c57d8bb30fc1bc1289ec332e70 Mon Sep 17 00:00:00 2001 From: Ashish Desai Date: Sun, 13 Nov 2022 17:51:43 -0500 Subject: [PATCH 1/3] completed burger discount function --- index.js | 27 ++++++++++++++++----------- package-lock.json | 21 ++++++++++++--------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 833600e1..a7d47ae5 100644 --- a/index.js +++ b/index.js @@ -15,12 +15,10 @@ 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(obj, nameValue, priceValue, categoryValue ){ + return `const ${obj} = {name: ${nameValue}, price: ${priceValue}, category: ${categoryValue}}` } - - +console.log(createMenuItem('lunchTacos', 'tacos', 8, 'Lunch')) /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 1b (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Invoke your function! @@ -31,8 +29,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('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 +48,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(burger.discount("teacher")); +console.log(burger.discount("public")); ///////////////Reviews (MVP)/////////////////// @@ -72,7 +76,7 @@ const reviews = [ Using the reviews array above: 1. log only Julius' feedback to the console - no function needed */ - +console.log(reviews[5].feedback); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 4 (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -81,7 +85,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(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. 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": { From 26a9bb7d75db312a7a933d958a4367156ed6eadf Mon Sep 17 00:00:00 2001 From: Ashish Desai Date: Thu, 15 Dec 2022 08:35:50 -0500 Subject: [PATCH 2/3] completed stretch assignments --- index.js | 75 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index a7d47ae5..227f0e79 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,12 @@ The function should: Example createMenuItem('tacos', 8, 'Lunch') should return {name: 'tacos', price: 8, category: 'Lunch'} */ -function createMenuItem(obj, nameValue, priceValue, categoryValue ){ - return `const ${obj} = {name: ${nameValue}, price: ${priceValue}, category: ${categoryValue}}` +function createMenuItem(name, price, category){ + const lunchTacos = {name , price, category}; + return lunchTacos; } -console.log(createMenuItem('lunchTacos', 'tacos', 8, 'Lunch')) +console.log(createMenuItem('tacos', 8, 'Lunch')) + /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 1b (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Invoke your function! @@ -100,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; } - - +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. @@ -117,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(getReviewByIndex(reviews, 0)) /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 7: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -136,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(getLastReview(reviews)); ///////////////πŸ”β˜•οΈπŸ½ STRETCHπŸ”β˜•οΈπŸ½//////////////////// @@ -157,11 +160,24 @@ 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 */ - } - +// When I can't return all matching criteria with for loop? +// function getReviewByRating(arr, num) { +// for (let i = 0; i < arr.length; i++ ) { +// if (arr[i].rating >= num && arr[i].rating < num + 1) { +// return arr[i]; +// } +// } +// } +// console.log("Stretch 1:", getReviewByRating(reviews, 4)); + +//or use 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: @@ -176,10 +192,24 @@ 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)); + + +// // unable to return list???? +// let longReviews = []; +// function getLongReviews(arr) { +// for (let i = 0; i < arr.length; i++) { +// longReviews.push(arr[i].feedback.length >= 15) +// } +// 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. @@ -198,6 +228,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 */ From 41131103b742ca717852f6197ee4fdc66a7914bb Mon Sep 17 00:00:00 2001 From: Ashish Desai Date: Thu, 15 Dec 2022 21:54:08 -0500 Subject: [PATCH 3/3] updated console log and resovled stretch assignments --- index.js | 82 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/index.js b/index.js index 227f0e79..0b2bdd97 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,7 @@ function createMenuItem(name, price, category){ const lunchTacos = {name , price, category}; return lunchTacos; } -console.log(createMenuItem('tacos', 8, 'Lunch')) +// console.log("Task 1a:", createMenuItem('tacos', 8, 'Lunch')) /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 1b (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -31,7 +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('lunchPizza', "pizza",5,"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. @@ -58,8 +58,8 @@ const burger = { } } } -console.log(burger.discount("teacher")); -console.log(burger.discount("public")); +// console.log("Task 2:", burger.discount("teacher")); +// console.log("Task 2:", burger.discount("public")); ///////////////Reviews (MVP)/////////////////// @@ -78,7 +78,7 @@ const reviews = [ Using the reviews array above: 1. log only Julius' feedback to the console - no function needed */ -console.log(reviews[5].feedback); +// console.log("Task 3:", reviews[5].feedback); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 4 (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -88,7 +88,7 @@ Reyna's feedback is missing! Use what you know to do the following: (no function */ reviews[reviews.length - 1]['feedback'] = "this place is chill with really cool people, great for getting work done on weekdays"; -console.log(reviews); +// 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. @@ -106,8 +106,8 @@ function addReview(array, name, rating, feedback){ array.push({name, rating, feedback}) return array; } -addReview(reviews, 'Billy', 2, 'Lame food!') -console.log(reviews); +// 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. @@ -123,7 +123,7 @@ Use the getReviewByIndex function below to do the following: 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(getReviewByIndex(reviews, 0)) +// console.log("Task 6:", getReviewByIndex(reviews, 0)) /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 7: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -142,7 +142,7 @@ Use the getLastReview function below to do the following: 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(getLastReview(reviews)); +// console.log("Task 7:", getLastReview(reviews)); ///////////////πŸ”β˜•οΈπŸ½ STRETCHπŸ”β˜•οΈπŸ½//////////////////// @@ -160,24 +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."} ] */ -// When I can't return all matching criteria with for loop? -// function getReviewByRating(arr, num) { -// for (let i = 0; i < arr.length; i++ ) { -// if (arr[i].rating >= num && arr[i].rating < num + 1) { -// return arr[i]; -// } -// } -// } +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 use 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)); +//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: @@ -192,25 +193,26 @@ Use the getLongReviews function below to do the following: ] */ -function getLongReviews(arr) { - const longReviews = arr.filter((item) => { - return item.feedback.length >= 15; - }) - return longReviews; -} -console.log("Stretch 2:", getLongReviews(reviews)); - - -// // unable to return list???? -// let longReviews = []; // function getLongReviews(arr) { -// for (let i = 0; i < arr.length; i++) { -// longReviews.push(arr[i].feedback.length >= 15) -// } +// 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.