Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
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
4 changes: 2 additions & 2 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let dog = {
Log the name and breed of this dog using dot notation.
*/

let dogName; // complete the code
let dogBreed; // complete the code
let dogName=dog.name; // complete the code
let dogBreed=dog.breed; // complete the code

console.log(`${dogName} is a ${dogBreed}`);

Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let capitalCities = {
*/

let myCountry = "UnitedKingdom";
let myCapitalCity; // complete the code
let myCapitalCity=capitalCities[myCountry]; // complete the code

console.log(myCapitalCity);

Expand Down
6 changes: 4 additions & 2 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ let basketballTeam = {
*/

// write code here


let sortedNames=(basketballTeam.topPlayers.sort());
for(let i=0; i<sortedNames.length; i++){
console.log(sortedNames[i]);
}
/* EXPECTED RESULT

Dennis Rodman
Expand Down
8 changes: 5 additions & 3 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ let capitalCities = {
name: "Beijing",
}
};

capitalCities.UnitedKingdom.population=8980000;
capitalCities.China.population=21500000;
capitalCities.peru={};
capitalCities.peru.name="Lima";
capitalCities.peru.population=9750000;
/*
Using dot notation:
- Change the value of UnitedKingdom's capital city population to 8980000.
Expand All @@ -22,8 +26,6 @@ let capitalCities = {
- Add a population of 9750000 to Peru's capital city.
*/

// write code here

console.log(capitalCities);

/* EXPECTED RESULT
Expand Down
8 changes: 4 additions & 4 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ let student = {
- Add a property to the student object for attendance
- Set the value of attendance to 90
*/

// write code here

student["attendance"]=90;
/*
- Write an "if" statement that changes the value of hasPassed to true
if the student has attendance that is equal or greater than 90
AND
exam score is above 60.
- Use bracket notation to change the value of hasPassed
*/
if(student["attendance"]>=90 && student["examScore"]>60){
student["hasPassed"]=true;
}

// write code here

console.log(student);

Expand Down
8 changes: 8 additions & 0 deletions 1-exercises/B-setting-values/week1.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "../../.."
}
],
"settings": {}
}
6 changes: 3 additions & 3 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ let car = {
yearsOld: 8,
};

console.log(car["colour"]);
console.log(car["colour"]);//The object car does not have the property colour(doesn't defined).so output is undefined.

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
console.log(`Hello ${user.firstName}`);//The object user does not have the property firstName so user.firstName is undefined.
}

let user = {
Expand All @@ -31,7 +31,7 @@ sayHelloToUser(user);
let myPet = {
animal: "Cat",
getName: function() {
"My pet's name is Fluffy";
"My pet's name is Fluffy"; //This function didn't return anything. so when we call this function the output is undefined.
},
};

Expand Down
4 changes: 3 additions & 1 deletion 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

let student = {
// write code here
getName: function(name){
console.log(`Student name: ${name}`)
}
}

student.getName("Daniel");
Expand Down
33 changes: 32 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,35 @@
You should write and log at least 5 recipes
*/

// write code here
let favoriteRecipes={
recipe1:{
title:"briyani",
serves:3,
ingredients:["rice","onion","tomato","mint","masala"]
},
recipe2:{
title:"idly",
serves:1,
ingredients:["rice","urud dhal"]
},
recipe3:{
title:"fishCurry",
serves:3,
ingredients:["fish","onion","tomato","chilly powder"]
},
recipe4:{
title:"vada",
serves:3,
ingredients:["urud dhal","onion","chilly"]
},
recipe5:{
title:"kova",
serves:2,
ingredients:["milk","sugar"]
}
};
console.log(favoriteRecipes.recipe1);
console.log(favoriteRecipes.recipe2);
console.log(favoriteRecipes.recipe3);
console.log(favoriteRecipes.recipe4);
console.log(favoriteRecipes.recipe5);
6 changes: 5 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let currency={};
for(let i=0; i<countryCurrencyCodes.length; i++){
currency[countryCurrencyCodes[i][0]]=countryCurrencyCodes[i][1];
}
return currency;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
10 changes: 9 additions & 1 deletion 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let missedItems={};
missedItems.items=[];
for(let i=0; i<recipe.ingredients.length; i++){
if(pantry.fridgeContents.includes(recipe.ingredients[i])===false && pantry.cupboardContents.includes(recipe.ingredients[i])===false){
missedItems.name=recipe.name;
missedItems.items.push(recipe.ingredients[i]);
}
}
return missedItems;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
13 changes: 12 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ const MENU = {
};

let cashRegister = {
// write code here
orderBurger:function(balance){
if(balance>=MENU.burger){
return (balance-MENU.burger)
}else
return balance;
},
orderFalafel:function(balance){
if(balance>=MENU.falafel){
return balance-MENU.falafel;
}else
return balance;
},
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
25 changes: 21 additions & 4 deletions 3-extra/1-count-words.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,28 @@

function countWords(string) {
const wordCount = {};

// write code here

return wordCount;
if(string){
let words=string.split(" ");
for(let i=0; i<words.length; i++){
let isNewWord=true;
for(let j=0; j<i; j++){
if(words[i]===words[j]){
wordCount[words[j]]+=1;
isNewWord=false;
break;
}
}
if(isNewWord===true){
wordCount[words[i]]=1;
}
}
return wordCount
}
else
return {};
}



/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm run extra-tests`
Expand Down