London Class 7 - Somayeh Karimi - JavaScript - core 2 - Week 1 - #45
London Class 7 - Somayeh Karimi - JavaScript - core 2 - Week 1#45DibaKarimi wants to merge 1 commit into
Conversation
|
|
||
| let recipes = {}; | ||
| let recipes = [ | ||
| { |
There was a problem hiding this comment.
You did a great job defining the list as an array and then each recipe as an object.
One suggestion would be to always use lowercase when naming your properties - that's the usual convention and you'll see it done that way consistently in documentation/tutorials etc.
So instead of Title, Serves, Ingredients have title, serves, ingredients.
| Ingredients: ["coffee", "milk", "honey"], | ||
| }, | ||
| ]; | ||
| recipes.forEach((Element)=>{ |
There was a problem hiding this comment.
What would be a more descriptive name for the variable instead of Element?
| console.log(Element.Title); | ||
| console.log("Serves: " + Element.Serves); | ||
| console.log("Ingredients:"); | ||
| for (Ingredient in Element.Ingredients) console.log(Element.Ingredients[Ingredient]); |
There was a problem hiding this comment.
Since ingredients is an array, you should use for... of... instead of for...in.... for...in... is usually used for objects.
https://betterprogramming.pub/what-is-the-difference-between-for-in-and-for-of-in-javascript-650952654e97?gi=e7681d52d21d
There was a problem hiding this comment.
I would also suggest that you format line 63 differently and use curly braces so it's easier to read.
e.g. if I used a for...of... loop it would look like:
for (Ingredient of Element.Ingredients) {
console.log(Ingredient);
}
| let books = []; | ||
| let books = [ | ||
| { | ||
| title: "The Hobbit", |
There was a problem hiding this comment.
Make sure you have the same level of indentation for each of the properties in the array.
| **/ | ||
|
|
||
| let books = []; | ||
| let books = [ |
There was a problem hiding this comment.
You've done a good job defining the array and the objects inside it. You also chose good property names and used correct casing.
| isRead:false | ||
| } | ||
| ]; | ||
|
|
There was a problem hiding this comment.
for...in... is usually used for objects. You should use for..of... for arrays.
You can read more about it here
https://medium.com/better-programming/what-is-the-difference-between-for-in-and-for-of-in-javascript-650952654e97
| */ | ||
| // Gather all week item names into this array | ||
| let weeklyGroceriesToBuy = []; | ||
| let weeklyGroceriesToBuy = Object.values(weeklyMealPlan).join(); |
There was a problem hiding this comment.
This does gather all of the items, but it stores them as a string. Can you think of a solution that gathers the items as an array?
Your list also contains duplicates -- for example Cheese appears twice. How could we remove those?
| // Gather weekend item names into this array | ||
| let weekendGroceriesToBuy = []; | ||
|
|
||
| let weekendGroceriesToBuy = weeklyMealPlan.saturday; |
There was a problem hiding this comment.
This works for this specific solution, but what if we update the meal plan to also include items on sunday? Also how would we make sure that there are no duplicated items?
| friend.friends.find((Element) => Element.name === "Stacie Villarreal") | ||
| ) | ||
| .map((friend) => Object.values(friend.name)) | ||
| .map((friend) => friend.join(" ")) |
There was a problem hiding this comment.
Good solution! But I think (name) => name.join(" ") would be a clearer way to name your variable here.
|
|
||
| */ | ||
|
|
||
| let arr = []; |
| people | ||
| .filter((friend) => | ||
| friend.friends.map((friendName) => { | ||
| if( friendName.skills.includes("Multi-tasking")) |
There was a problem hiding this comment.
Good solution! Can you think of a solution using filter instead of an if statement?
|
Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback. |
Your Details
Homework Details