Skip to content

web-module-challenge-objects finished #237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 47 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ The function should:

Example createMenuItem('tacos', 8, 'Lunch') should return {name: 'tacos', price: 8, category: 'Lunch'}
*/

function createMenuItem(/*Your code here*/){
/*Your code here*/
// name, price, category
function createMenuItem(name, price, category){
return {name, price, category};
}

/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 1b: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -29,6 +29,16 @@ 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"}
*/

const pizza = createMenuItem('pizza', 2, 'Lunch');
const bagel = createMenuItem('bagel', 1.5, 'Breakfast');
const smoothie = createMenuItem('smoothie', 3, 'Drink');

console.log(smoothie);
console.log(bagel);
console.log(pizza);
// invoke function 3 times




/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 2: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Expand All @@ -43,14 +53,26 @@ 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",

}

//method goes here
discount: function(string){
if(string === 'teacher'){
return this.price * .75;
} else {
return this.price * .9;
}

}

//
}

console.log(burger.discount("teacher"));

///////////////Reviews (MVP)///////////////////
const reviews = [
Expand All @@ -69,16 +91,17 @@ Using the reviews array above:
1. log only Julius' feedback to the console - no function needed
*/


// just console log


/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 4: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
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[7].feedback = "this place is chill with really cool people, great for getting work done on weekdays";
console.log(reviews[7].feedback);
//object.the new key (value)



Expand All @@ -91,25 +114,27 @@ Write a function that creates an object with name, rating, feedback, add the new
4. should return the resulting array
*/

function addReview(/*Your Code Here */){
/*Your Code Here */
function addReview(array, name, rating, feedback){
array.push(name, {rating}, feedback);
return array; //array.push({})
}

console.log(addReview(reviews, 'Daniela', 5, 'Beautiful atmosphere and wonderful vegan options!'));
/* 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀 Task 6: 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀
Write a function to return a review based on the index of the review in the array.

Use the getReviewByIndex function below to do the following:
1. Receive an array
2. Receive a number which is the desired index in the array
2. Receive a number which is the desired index in the array (array[specificnumber].value)
3. The function should return the following string: "{name} gave the restaurant a {rating} star review, and their feedback was: {feedback}"
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*/
//array / number
function getReviewByIndex(array, i) {
return `${array[i].name} gave the restaurant a ${array[i].rating} star review, and their feedback was: ${array[i].feedback}"`;

}

console.log(getReviewByIndex(reviews, 0));



Expand All @@ -124,11 +149,15 @@ Use the getLastReview function below to do the following:
For example: getLastReview(reviews) would return: "Reyna gave the restaurant a 3.5 star review, and their feedback was: this place is chill with really cool people, great for getting work done on weekdays".
*/

// 2 para array
//array[array.length-1] - to get last in the array
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}`


function getLastReview(/*Your code here*/) {
/*Your code here*/
}

console.log(getLastReview(reviews));


///////////////🍔☕️🍽 STRETCH🍔☕️🍽////////////////////
Expand Down
Loading