London_10-Saliha_Popal-JavaScript-Core-2-Coursework-Week1#244
London_10-Saliha_Popal-JavaScript-Core-2-Coursework-Week1#244SalihaPopal wants to merge 1 commit intoCodeYourFuture:mainfrom
Conversation
| let dogName; // complete the code | ||
| let dogBreed; // complete the code | ||
| let dogName = "Spot"; // complete the code | ||
| let dogBreed = "Dalmatian"; // complete the code |
There was a problem hiding this comment.
for these two you should access the dog object by doing dog.name or dog.breed
|
|
||
| let myCountry = "UnitedKingdom"; | ||
| let myCapitalCity; // complete the code | ||
| let myCapitalCity = "London"; // complete the code |
There was a problem hiding this comment.
here you should use the alternate method of accessing object data, which would be capitalCities[myCountry]
|
|
||
| // write code here | ||
|
|
||
| console.log(basketballTeam.topPlayers) |
There was a problem hiding this comment.
here you are expected to sort through this list of basketballTeam.topPlayers and then print each of the players on a new line. You can do that with array methods .sort() and .forEach()
| console.log("Ingredients:"); | ||
| for (let i = 0; i < recipe5.ingredients.length; i++) { | ||
| console.log(recipe5.ingredients[i]); | ||
| } |
There was a problem hiding this comment.
you can avoid repeating yourself here by moving these console.log and for loop into another function which takes a recipe as an argument. e.g. function logRecipe(recipe) { ... }
| words.forEach((word) => { | ||
|
|
||
| if(string == ""){ | ||
| return wordCount |
There was a problem hiding this comment.
there is no need to use return when using forEach because the return value is discarded anyway (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
|
good work! |
| for (let i = 0; i < recipe1.ingredients.length; i++) { | ||
| console.log(recipe1.ingredients[i]); | ||
| } | ||
|
|
There was a problem hiding this comment.
.forEch() is also the best mothod.
recipe1.ingredients.forEach(ingredient) => {
console.log(ingredient);
}
| return lookup | ||
| } | ||
| console.log(createLookup(COUNTRY_CURRENCY_CODES)); | ||
|
|
There was a problem hiding this comment.
Or we can write the code as following:
function createLookup(countryCurrencyCodes) {
let currencyCodeLookup = {};
for (let countryCurrencyCode of countryCurrencyCodes) {
let countryCode = countryCurrencyCode[0];
let currencyCode = countryCurrencyCode[1];
currencyCodeLookup[countryCode] = currencyCode;
};
return currencyCodeLookup;
}
There was a problem hiding this comment.
I think your original solution is better, but this other solution is also nice and clear.
| return balance; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
const MENU = {
burger: 6.5,
falafel: 7.25,
};
let cashRegister = {
orderBurger: function(balance) {
let finalBalance = balance;
let isBalanceBigEnough = balance - MENU.burger >= 0;
if (isBalanceBigEnough) {
finalBalance = balance - MENU.burger;
}
return finalBalance;
},
orderFalafel: function(balance) {
let finalBalance = balance;
let isBalanceBigEnough = balance - MENU.falafel >= 0;
if (isBalanceBigEnough) {
finalBalance = balance - MENU.falafel;
}
return finalBalance;
},
};
There was a problem hiding this comment.
I like your original solution better here too
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?