diff --git a/index.js b/index.js index 833600e1..8ccb58ba 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,42 +50,73 @@ 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", + discount: function (discountType) { + if (discountType === "teacher" || discountType === "student") { + return this.price * 0.75; + } else { + return this.price * 0.9; + } + }, +}; ///////////////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 */ - +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. @@ -94,13 +129,16 @@ 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: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Write a function to return a review based on the index of the review in the array. @@ -111,13 +149,11 @@ 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: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Write a function to get information about the most recent (last) review called `getLastReview` @@ -130,12 +166,10 @@ 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πŸ”β˜•οΈπŸ½//////////////////// @@ -153,11 +187,16 @@ 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: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ Use the getLongReviews function below to do the following: 1. Receive the array that holds all the reviews @@ -171,10 +210,15 @@ 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: πŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺπŸ’ͺ This stretch goal does not use the reviews data! You create your own object in this stretch goal. @@ -193,17 +237,21 @@ 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 πŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸ›‘ */ -function foo(){ - console.log('its working'); - return 'bar'; +function foo() { + console.log("its working"); + return "bar"; } module.exports = { foo, @@ -212,4 +260,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",