From 2389df519cdc449ebde00229f45f70824efbc556 Mon Sep 17 00:00:00 2001 From: David Stinnett Date: Thu, 1 Jun 2023 20:49:15 -0400 Subject: [PATCH 1/4] added function that creates objexts --- index.js | 123 +++++++++++++++++++++++++--------------------- package-lock.json | 4 +- 2 files changed, 69 insertions(+), 58 deletions(-) diff --git a/index.js b/index.js index 833600e1..86bed651 100644 --- a/index.js +++ b/index.js @@ -3,8 +3,12 @@ /*When doing these tasks, we recommend using console.log to test the output of your code to make sure it works correctly.*/ ///////////////Menu Items (MVP)/////////////////// -const latte = {name: "Cafe Latte", price: 4, category: "Drinks"}; -const breakfastBurrito = {name: "Breakfast Burrito", price: 16, category:"Breakfast"}; +const latte = { name: "Cafe Latte", price: 4, category: "Drinks" }; +const breakfastBurrito = { + name: "Breakfast Burrito", + price: 16, + category: "Breakfast", +}; /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 1a: Make a function that builds objectsπŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Add to the function createMenuItems below so it will create objects following the same format found above for latte and breakfastBurrito (name, price, category). @@ -15,13 +19,15 @@ 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) { + let menuItem = { + name: name, + price: price, + category: category, + }; + return menuItem; } - - /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 1b (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Invoke your function! Test your createMenuItems function by doing the following: @@ -32,8 +38,6 @@ 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"} */ - - /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ 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. @@ -46,43 +50,64 @@ Using the burger object below do the following: For example: burger.discount("teacher") would return 13.5 and burger.discount("public") would return 16.2 */ - const burger = { - name: "Burger", - price: 18, - category: "Lunch", - -} - - + name: "Burger", + price: 18, + category: "Lunch", +}; ///////////////Reviews (MVP)/////////////////// const reviews = [ - {name: "Daniela", rating: 5, feedback:"Beautiful atmosphere and wonderful vegan options!"}, - {name: "Jack", rating: 3, feedback:"A little too hipster for my taste, but the burger was decent, if overpriced"}, - {name: "Miranda", rating: 4, feedback:"fun trivia and cool vibes"}, - {name: "Wen", rating: 4.5, feedback:"I don't leave my house often, but when I do, it's for this place. Highly reccomend."}, - {name: "Brett", rating: 3, feedback: "great selection of snacks and a nice cafe area to get work done during the day."}, - {name: "Julius", rating: 2, feedback: "I was largely unimpressed by this venue. Nothing special on the menu and too expensive. The atmosphere is polarizing, and not for me, but I think some would like it." }, - {name: "Lauren", rating: 4, feedback: "Absolutely love that they have karaoke Fridays! Food and drink selection is okay."}, - {name: "Reyna", rating: 3.5, feedback: ""}, -] + { + name: "Daniela", + rating: 5, + feedback: "Beautiful atmosphere and wonderful vegan options!", + }, + { + name: "Jack", + rating: 3, + feedback: + "A little too hipster for my taste, but the burger was decent, if overpriced", + }, + { name: "Miranda", rating: 4, feedback: "fun trivia and cool vibes" }, + { + name: "Wen", + rating: 4.5, + feedback: + "I don't leave my house often, but when I do, it's for this place. Highly reccomend.", + }, + { + name: "Brett", + rating: 3, + feedback: + "great selection of snacks and a nice cafe area to get work done during the day.", + }, + { + name: "Julius", + rating: 2, + feedback: + "I was largely unimpressed by this venue. Nothing special on the menu and too expensive. The atmosphere is polarizing, and not for me, but I think some would like it.", + }, + { + name: "Lauren", + rating: 4, + feedback: + "Absolutely love that they have karaoke Fridays! Food and drink selection is okay.", + }, + { name: "Reyna", rating: 3.5, feedback: "" }, +]; /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 3 (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Using the reviews array above: 1. log only Julius' feedback to the console - no function needed */ - - /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 4 (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Reyna's feedback is missing! Use what you know to do the following: (no function needed) 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 */ - - /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ 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. @@ -94,13 +119,10 @@ Use the addReview function below to do the following: 4. Return the updated array */ - -function addReview(/*Your Code Here */){ +function addReview(/*Your Code Here */) { /*Your Code Here */ } - - /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 6: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Write a function to return a review based on the index of the review in the array. @@ -111,13 +133,10 @@ Use the getReviewByIndex function below to do the following: For example: getReviewByIndex(reviews,0) would return: "Daniela gave the restaurant a 5 star review, and their feedback was: Beautiful atmosphere and wonderful vegan options!" */ - function getReviewByIndex(/*Your code here*/) { /*Your code here*/ } - - /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 7: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Write a function to get information about the most recent (last) review called `getLastReview` @@ -130,12 +149,9 @@ Use the getLastReview function below to do the following: NOTE: her feedback should not be blank if task 4 was done correctly */ - function getLastReview(/*Your code here*/) { /*Your code here*/ -} - - +} ///////////////πŸ”β˜•οΈπŸ½ STRETCHπŸ”β˜•οΈπŸ½//////////////////// @@ -153,11 +169,10 @@ Use the getReviewsByRating function below to do the following: ] */ - function getReviewByRating(/* code here */) { - /* code here */ - } +function getReviewByRating(/* code here */) { + /* code here */ +} - /* πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ STRETCH 2: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ Use the getLongReviews function below to do the following: 1. Receive the array that holds all the reviews @@ -172,9 +187,8 @@ Use the getLongReviews function below to do the following: */ function getLongReviews(/* code here */) { - /* code here */ - } - + /* code here */ +} /* πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ STRETCH 3: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ This stretch goal does not use the reviews data! You create your own object in this stretch goal. @@ -193,17 +207,14 @@ 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 */ - + /* code here */ } - /* πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘ Please do not modify anything below this line πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘ */ -function foo(){ - console.log('its working'); - return 'bar'; +function foo() { + console.log("its working"); + return "bar"; } module.exports = { foo, @@ -212,4 +223,4 @@ module.exports = { addReview, getReviewByIndex, getLastReview, -} +}; 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", From 2253a514b427328c2052a1c10947fd89a7696fb2 Mon Sep 17 00:00:00 2001 From: David Stinnett Date: Thu, 1 Jun 2023 20:53:34 -0400 Subject: [PATCH 2/4] did some more of the mini challenge tasks --- index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 86bed651..ca2d8f09 100644 --- a/index.js +++ b/index.js @@ -54,6 +54,17 @@ const burger = { name: "Burger", price: 18, category: "Lunch", + discount: function (discountType) { + if ( + discountType === "teacher" || + discountType === "student" || + discountType === "public" + ) { + return this.price * 0.75; + } else { + return this.price * 0.9; + } + }, }; ///////////////Reviews (MVP)/////////////////// @@ -102,11 +113,14 @@ Using the reviews array above: 1. log only Julius' feedback to the console - no function needed */ +console.log(reviews[4].feedback); + /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 4 (not auto-tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Reyna's feedback is missing! Use what you know to do the following: (no function needed) 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[5].feedback = + "this place is chill with really cool people, great for getting work done on weekdays"; /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ 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. From 604d50af397278832569bc98c967dfc4683ccd7d Mon Sep 17 00:00:00 2001 From: David Stinnett Date: Thu, 1 Jun 2023 20:58:20 -0400 Subject: [PATCH 3/4] completed challenges, working on stretch goals now --- index.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index ca2d8f09..8758fa21 100644 --- a/index.js +++ b/index.js @@ -55,11 +55,7 @@ const burger = { price: 18, category: "Lunch", discount: function (discountType) { - if ( - discountType === "teacher" || - discountType === "student" || - discountType === "public" - ) { + if (discountType === "teacher" || discountType === "student") { return this.price * 0.75; } else { return this.price * 0.9; @@ -133,8 +129,14 @@ Use the addReview function below to do the following: 4. Return the updated array */ -function addReview(/*Your Code Here */) { - /*Your Code Here */ +function addReview(array, name, rating, feedback) { + let review = { + name: name, + rating: rating, + feedback: feedback, + }; + array.push(review); + return array; } /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 6: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -147,8 +149,9 @@ Use the getReviewByIndex function below to do the following: For example: getReviewByIndex(reviews,0) would return: "Daniela gave the restaurant a 5 star review, and their feedback was: Beautiful atmosphere and wonderful vegan options!" */ -function getReviewByIndex(/*Your code here*/) { - /*Your code here*/ +function getReviewByIndex(array, index) { + let review = array[index]; + return `${review.name} gave the restaurant a ${review.rating} star review, and their feedback was: ${review.feedback}`; } /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 7: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -163,8 +166,9 @@ Use the getLastReview function below to do the following: NOTE: her feedback should not be blank if task 4 was done correctly */ -function getLastReview(/*Your code here*/) { - /*Your code here*/ +function getLastReview(array, index) { + let review = array[array.length - 1]; + return `${review.name} gave the restaurant a ${review.rating} star review, and their feedback was: ${review.feedback}`; } ///////////////πŸ”β˜•οΈπŸ½ STRETCHπŸ”β˜•οΈπŸ½//////////////////// @@ -183,8 +187,14 @@ Use the getReviewsByRating function below to do the following: ] */ -function getReviewByRating(/* code here */) { - /* code here */ +function getReviewByRating(array, rating) { + let reviews = []; + for (let i = 0; i < array.length; i++) { + if (array[i].rating >= rating && array[i].rating < rating + 1) { + reviews.push(array[i]); + } + } + return reviews; } /* πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ STRETCH 2: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ From ca690daee4c1255aceded07e700320ee14050e03 Mon Sep 17 00:00:00 2001 From: David Stinnett Date: Thu, 1 Jun 2023 20:59:34 -0400 Subject: [PATCH 4/4] finished stretch goals for this section --- index.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 8758fa21..8ccb58ba 100644 --- a/index.js +++ b/index.js @@ -210,8 +210,14 @@ Use the getLongReviews function below to do the following: ] */ -function getLongReviews(/* code here */) { - /* code here */ +function getLongReviews(array) { + let reviews = []; + for (let i = 0; i < array.length; i++) { + if (array[i].feedback.split(" ").length > 15) { + reviews.push(array[i]); + } + } + return reviews; } /* πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ STRETCH 3: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ @@ -231,8 +237,15 @@ 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 */ +function carMaker(odometer) { + let car = { + odometer: odometer, + drive: function (distance) { + this.odometer += distance; + return this.odometer; + }, + }; + return car; } /* πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘ Please do not modify anything below this line πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘ */