-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
222 lines (165 loc) Β· 10.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*MAKE SURE TO RETURN ALL OF THE ANSWERS ON THESE TASKS, IF YOU DON'T, THE AUTOGRADER WILL NOT WORK*/
/*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"};
/* ππππππππππ 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).
The function should:
1. Receive values for the object that will be created as parameters
2. Create and return an object using the received values
Example createMenuItem('tacos', 8, 'Lunch') should return {name: 'tacos', price: 8, category: 'Lunch'}
*/
function createMenuItem(name, price, category){
return {name, price, category};
}
/* ππππππππππ Task 1b: ππππππππππ
Invoke your function!
Test your createMenuItems function by doing the following:
1. Pass values to createMenuItems in order to create the objects (menu items)
2. Create at least 3 menu items (objects) of your choosing making sure they have name, price, and category keys
3. Log each returned object to the console
For example: createMenuItem("pizza",5,"lunch") would return this as the object: {name:"Pizza",price:5,category:"lunch"}
*/
console.log(createMenuItem('pizza', 5, 'lunch'));
console.log(createMenuItem('waffles', 10, 'breakfast'));
console.log( createMenuItem('steak', 15, 'dinner'));
/* ππππππππππ 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 a string received as a parameter.
Using the burger object below do the following:
1. Add a method called discount to the burger object
2. The discount method should accept a string as a parameter (example: "teacher", "student", or "public")
3. Depending on the string, it will return the correct discounted price
4. Check your work by invoking the function and passing in 'teacher', 'student', or 'public' as your arguments to ensure they are returning the correct price.
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",
discount: function (person){
if(person === 'student' || person === 'teacher'){
return this.price - (this.price* 0.25);
}else if (person === 'public'){
return this.price - (this.price* 0.1);
}
}
}
///////////////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: ""},
]
/* ππππππππππ Task 3: ππππππππππ
Using the reviews array above:
1. log only Julius' feedback to the console - no function needed
*/
console.log(reviews[5].feedback);
/* ππππππππππ 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);
/* ππππππππππ 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
the addReview function below to do the following:
1. Receive an array
2. Receive the following object keys name, rating, feedback
3. The function should push the following object to the array: {name: 'Daniela', rating: 5, review: 'Beautiful atmosphere and wonderful vegan options!' }
4. should return the resulting array
*/
function addReview(array, name, rating, feedback){
array.push({name, rating, feedback});
return array;
}
/* ππππππππππ 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
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(array, number) {
return `${array[number].name} gave the restaurant a ${array[number].rating} star review, and their feedback was: ${array[number].feedback}`
}
/* ππππππππππ Task 7: ππππππππππ
Write a function to get information about the most recent (last) review called `getLastReview`
Use the getLastReview function below to do the following:
1. Receive an array of objects as a parameter
2. Return the last index as a string in the format: "{name} gave the restaurant a {rating} star review, and their feedback was: {feedback}"
3. Invoke the function with the reviews array as the argument
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".
*/
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}`
}
///////////////πβοΈπ½ STRETCHπβοΈπ½////////////////////
/** πͺπͺπͺπͺπͺπͺπͺπͺπͺπͺ STRETCH 1: πͺπͺπͺπͺπͺπͺπͺπͺπͺπͺ
Use the getReviewsByRating function below to do the following:
1. Receive the array that holds all the reviews
2. Receive a rating
3. Return an array with all the reviews in that range
For example: getReviewByRating(reviews, 4) would return these reviews in the 4 range (4-4.9):
[
{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:"Lauren", rating: 4, feedback: "Absolutely love that they have karaoke Fridays! Food and drink selection is okay."}
]
*/
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
2. Return an array with all the reviews that have more than 15 words in their feedback
For example: getLongReviews(reviews) would return:
[
{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." }
]
*/
function getLongReviews(/* code here */) {
/* code here */
}
/* πͺπͺπͺπͺπͺπͺπͺπͺπͺπͺ STRETCH 3: πͺπͺπͺπͺπͺπͺπͺπͺπͺπͺ
This stretch goal does not use the reviews data! You create your own object in this stretch goal.
Use the carMaker function below to do the following:
1. Receive a value representing the odometer (how many miles it's been driven) and use that when creating the object
2. Create a drive method inside the object that increases the odometer value
3. Return the object
4. The returned object with the odometer value should have the following characteristics:
a. The drive method which, when called, takes a distance value as its parameter
b. The drive method should also cause the odometer value in the object to be increased by the distance
c. Then the drive method should return the updated value of the odometer
For example: Let's say we created the object in the variable car1 with an odometer value of 10.
Then we called car1.drive(100)
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 */
}
/* πππππ Please do not modify anything below this line πππππ */
function foo(){
console.log('its working');
return 'bar';
}
module.exports = {
foo,
createMenuItem,
burger,
addReview,
getReviewByIndex,
getLastReview,
}