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
6 changes: 4 additions & 2 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ 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;
let dogBreed=dog.breed;

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



/* EXPECTED RESULT

Spot is a Dalmatian
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=['London'];

console.log(myCapitalCity);

Expand Down
4 changes: 2 additions & 2 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ let basketballTeam = {
address: "1901 W Madison St",
},
};

let sortTeam = basketballTeam.topPlayers.sort();
sortTeam.forEach(player =>console.log(player));
/*
Write code that
- accesses the basketball team's top players array
- sorts the top players in alphabetical order
- console.logs the name of each player on a new line
*/

// write code here


/* EXPECTED RESULT
Expand Down
14 changes: 13 additions & 1 deletion 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ let capitalCities = {
UnitedKingdom: {
name: "London",
population: 20,

},
China: {
name: "Beijing",
},

Peru:{

}
};

Expand All @@ -22,7 +27,14 @@ let capitalCities = {
- Add a population of 9750000 to Peru's capital city.
*/

// write code here
capitalCities.UnitedKingdom.population= 8980000
capitalCities.China.population=2150000

capitalCities.Peru= {
name : "Lima",
population : 9750000
}


console.log(capitalCities);

Expand Down
10 changes: 6 additions & 4 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
let student = {
name: "Reshma Saujani",
examScore: 65,
hasPassed: false
hasPassed: false,

};

/*
Expand All @@ -15,7 +16,7 @@ let student = {
- 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
Expand All @@ -25,8 +26,9 @@ let student = {
- Use bracket notation to change the value of hasPassed
*/

// write code here

if(student.attendance >= 90 && student.examScore> 60 ){
student['hasPassed']=true
}
console.log(student);

/* EXPECTED RESULT
Expand Down
4 changes: 4 additions & 0 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let car = {
};

console.log(car["colour"]);
//as we did not diclre color for the car//

// Example 2
function sayHelloToUser(user) {
Expand All @@ -27,6 +28,8 @@ let user = {

sayHelloToUser(user);

// as we have 'name' in our object and gave that value but we called 'firstName' in line 22 and they are not match

// Example 3
let myPet = {
animal: "Cat",
Expand All @@ -36,3 +39,4 @@ let myPet = {
};

console.log(myPet.getName());
// there is not return statement in our function//
7 changes: 5 additions & 2 deletions 1-exercises/D-object-methods/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
*/

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

};

student.getName("Daniel");

Expand Down
12 changes: 12 additions & 0 deletions 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,17 @@

You should write and log at least 5 recipes
*/
let favoriteRecipe ={
title : 'Mole',
servings : 2 ,
ingredients :['cinnamon' , 'cumin' , 'cocoa' ]
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you use a linting service to make the formatting easier in vscode? https://eslint.org/

console.log(favoriteRecipe.title);
console.log(`Serves: ${favoriteRecipe.servings}`);
console.log('Ingredients:')
favoriteRecipe.ingredients.forEach((item) => {
console.log(item);
});

// write code here
9 changes: 8 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,14 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
let currencyCodeLook ={};

for (let countryCurrencyCode of countryCurrencyCodes){
let countryCode = countryCurrencyCode[0];
let countryCurrency = countryCurrencyCode[1];
currencyCodeLook[countryCode]=countryCurrency;
};
return currencyCodeLook;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using for loops you could also use this https://www.w3schools.com/jsref/jsref_foreach.asp

}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
15 changes: 12 additions & 3 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -19,9 +19,18 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
}
let shoppingList = recipe.ingredients.filter(
(ingredient) => {
return !pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)

}
);
return {
name : recipe.name,
items : shoppingList,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really clear function :)

}
/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down
18 changes: 17 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@ const MENU = {

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

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
35 changes: 25 additions & 10 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,56 @@ function convertScoreToGrade(score) {
passes.
*/
test("a score of 83 is grade A", () => {
expect(convertScoreToGrade(83), "Z");
expect(convertScoreToGrade(83)).toBe ("A");
});

/*
The rest of the tests have comments describing what to test and you need to
write a matching test
*/

test.skip("a score of 71 is grade B", () => {
/* Remove the .skip above, then write the test body. */
});
test("a score of 71 is grade B", () => {
expect(convertScoreToGrade(71)).toBe ("B");
})
/*
Write a test that checks a score of 68 is grade C
*/

test ("a score of 68 is grade C" ,() => {
expect(convertScoreToGrade(68)).toBe("C");
});
/*
Write a test that checks a score of 55 is grade D
*/

test ("a score of 55 is grade D" ,() => {
expect(convertScoreToGrade(55)).toBe("D");
});
/*
Write a test that checks a score of 68 is grade C
*/

test ("a score of 68 is grade C" ,() => {
expect(convertScoreToGrade(68)).toBe("C");
});
/*
Write a test that checks a score of 55 is grade D
*/

test ("a score of 55 is grade D" ,() => {
expect(convertScoreToGrade(55)).toBe("D");
});
/*
Write a test that checks a score of 49 is grade E
*/

test ("a score of 49 is grade E" ,() => {
expect(convertScoreToGrade(49)).toBe("E");
});
/*
Write a test that checks a score of 30 is grade E
*/

test ("a score of 30 is grade E" ,() => {
expect(convertScoreToGrade(30)).toBe("E");
});
/*
Write a test that checks a score of 70 is grade B
*/
test ("a score of 70 is grade B" ,() => {
expect(convertScoreToGrade(70)).toBe("B");
});
39 changes: 34 additions & 5 deletions 2-mandatory/6-writing-tests-advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
trainee has completed.
*/

function convertScoreToGrade() {
function convertScoreToGrade(score) {
let grade = null;

if (score >= 80) {
Expand Down Expand Up @@ -55,15 +55,25 @@ function formatCourseworkResult(trainee) {
score: 63
}
*/

test ("a score of 63 is grade C" ,() => {
const trainee = { name : 'Xin' , score :63};
expect(formatCourseworkResult (trainee)).toEqual(
"Xin's coursework was marked as grade C."
);
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Mona",
score: 78
}
*/

test ('a score of 78 is grade B' , () => {
const trainee = { name: 'Mona' , score : 78} ;
expect (formatCourseworkResult (trainee)).toEqual(
"Mona's coursework was marked as grade B."
);
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
Expand All @@ -73,19 +83,38 @@ function formatCourseworkResult(trainee) {
subjects: ["JavaScript", "React", "CSS"]
}
*/

test('a score of 49 is grade E', () =>{
const trainee ={
name :'Ali',
score : 49 ,
age : 33,
subjects : ['JavaScript' , 'React' , 'CSS'],
};
expect(formatCourseworkResult(trainee)).toEqual(
"Ali's coursework was marked as grade E."
);
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
score: 90,
age: 29
}
*/

test ('object without name property will face error' , () =>{
const trainee ={score:90 , age:29};
expect(formatCourseworkResult(trainee)).toEqual('Error: No trainee name!');
});
/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
*/
test('object without score property will face error' ,() => {
const trainee ={ name :'Amen' , subjects :['HTML' , ' CSS', 'Databases']};
expect(formatCourseworkResult(trainee)).toEqual(
'Error: Coursework percent is not a number!'
);
});