-
-
Notifications
You must be signed in to change notification settings - Fork 264
Glasgow Class 6 - Malkit Benning - JavaScript Core 2 - Week 1 #217
base: main
Are you sure you want to change the base?
Changes from all commits
df343b0
489968e
6d9908c
5d6b83a
a42de1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,24 +15,27 @@ let car = { | |
| }; | ||
|
|
||
| console.log(car["colour"]); | ||
| //there is no property called "colour" in car object | ||
|
|
||
| // Example 2 | ||
| function sayHelloToUser(user) { | ||
| console.log(`Hello ${user.firstName}`); | ||
| } | ||
|
|
||
| let user = { | ||
| name: "Mira" | ||
| name: "Mira", | ||
| }; | ||
|
|
||
| sayHelloToUser(user); | ||
| //you are calling a function that does not 'return' a value | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: The fact that the function doesn't return a value here doesn't matter. It will still run and the function includes a |
||
|
|
||
| // Example 3 | ||
| let myPet = { | ||
| animal: "Cat", | ||
| getName: function() { | ||
| getName: function () { | ||
| "My pet's name is Fluffy"; | ||
| }, | ||
| }; | ||
|
|
||
| console.log(myPet.getName()); | ||
| // the getName function does not 'return' a value | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,11 @@ const COUNTRY_CURRENCY_CODES = [ | |
| ]; | ||
|
|
||
| function createLookup(countryCurrencyCodes) { | ||
| // write code here | ||
| currencyObj = {}; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: You must use |
||
| countryCurrencyCodes.forEach((element) => { | ||
| currencyObj[element[0]] = element[1]; | ||
| }); | ||
| return currencyObj; | ||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
|
|
||
| The createShoppingList function should return an object with two properties: | ||
| - "name" of the recipe, which is a string, | ||
| - "items", which is an arry of the missing ingredients that need to be on the shopping list | ||
| - "items", which is an array of the missing ingredients that need to be on the shopping list | ||
| */ | ||
|
|
||
| let pantry = { | ||
|
|
@@ -19,7 +19,25 @@ let pantry = { | |
| }; | ||
|
|
||
| function createShoppingList(recipe) { | ||
| // write code here | ||
| let shoppingList = {}; | ||
| let recipeName = recipe.name; | ||
| let missingIngredients = []; | ||
| console.log("recipe name ", recipeName); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: Don't leave |
||
| let recipeIngredients = recipe.ingredients; | ||
| recipeIngredients.forEach((ingredient) => { | ||
| if ( | ||
| pantry.cupboardContents.includes(ingredient) || | ||
| pantry.fridgeContents.includes(ingredient) | ||
| ) { | ||
| } else { | ||
| missingIngredients.push(ingredient); | ||
| } | ||
| if (missingIngredients.length > 0) { | ||
| shoppingList.items = missingIngredients; | ||
| shoppingList.name = recipeName; | ||
| } | ||
| }); | ||
| return shoppingList; | ||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: This would be slightly cleaner by omitting the parenthesis around player
This is possible as the arrow function takes a single paramter