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
13 changes: 12 additions & 1 deletion 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ let capitalCities = {
Peru: "Lima"
};

let person = {
head: "Brain",
hand: "Nails",
lags:

}


// console.log(capitalCities.China);
// console.log(capitalCities.Peru);

/*
You have an object, capitalCities, that contains key/value pairs of countries and their capital cities.
Log the value for the property assigned to the variable myCountry using bracket notation.
Do not use dot notation for this exercise!
*/

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

console.log(myCapitalCity);

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

// write code here

let sortedName = basketballTeam.topPlayers.sort();
console.log(sortedName[0])
console.log(sortedName[1])
console.log(sortedName[2])

/* EXPECTED RESULT

Expand Down
6 changes: 6 additions & 0 deletions 1-exercises/B-setting-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ let capitalCities = {
*/

// write code here
capitalCities.UnitedKingdom.population = 8980000;
capitalCities.China.population = 21500000;
capitalCities.Peru = {
name: "Lima",
population: 9750000,
}

console.log(capitalCities);

Expand Down
1 change: 1 addition & 0 deletions 1-exercises/B-setting-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let student = {
*/

// write code here
07767895492

/*
- Write an "if" statement that changes the value of hasPassed to true
Expand Down
13 changes: 12 additions & 1 deletion 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@ const COUNTRY_CURRENCY_CODES = [
];

function createLookup(countryCurrencyCodes) {
// write code here
const lookup ={}
countryCurrencyCodes.forEach(([country, currency]) => {
lookup[country] = currency;
});
return lookup;
}


const lookup = createLookup(COUNTRY_CURRENCY_CODES);
console.log(lookup);




/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 2-currency-code-lookup.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down
17 changes: 16 additions & 1 deletion 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here

//declere shoppoingList object
let shoppoingList = {
name: recipe.name,
items: [],
}
recipe.ingredients.forEach((ingredient) => {
if (!pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient)){
shoppoingList.items.push(ingredient)}
} );
shoppoingList.name = recipe.name
return shoppoingList
}
// go throth all elements in the recepi.ingrediants array
// RTCSessionDescription.ingredients.forEach(function(ingrediant) {

// })

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
Expand Down
25 changes: 24 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,32 @@ const MENU = {
};

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

orderFalafel(balance) {
if (balance >= MENU.falafel) {
balance -= MENU.falafel;
}
return balance;
}
}


let balance = 10;

// order a burger
balance = cashRegister.orderBurger(balance);

// order falafel
balance = cashRegister.orderFalafel(balance);

console.log(balance);

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down
49 changes: 19 additions & 30 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,31 @@ function convertScoreToGrade(score) {
The first test has been written for you. You need to fix the test so that it
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
*/

/*
Write a test that checks a score of 55 is grade 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");
});
90 changes: 48 additions & 42 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 @@ -48,44 +48,50 @@ function formatCourseworkResult(trainee) {
- (Reminder: You must have run `npm install` one time before this will work!)
*/

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Xin",
score: 63
}
*/

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Mona",
score: 78
}
*/

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Ali",
score: 49,
age: 33,
subjects: ["JavaScript", "React", "CSS"]
}
*/

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
score: 90,
age: 29
}
*/

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Aman",
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("formatCourseworkResult should return correct string for a trainee with name 'Xin' and score 63", () => {
const trainee = {
name: "Xin",
score: 63,
};
expect(formatCourseworkResult(trainee)).toBe(
"Xin's coursework was marked as grade C."
);
});

test("formatCourseworkResult should return correct string for a trainee with name 'Mona' and score 78", () => {
const trainee = {
name: "Mona",
score: 78,
};
expect(formatCourseworkResult(trainee)).toBe(
"Mona's coursework was marked as grade B."
);
});

test("formatCourseworkResult should return 'Error: Coursework percent is not a number!' for a trainee without score property", () => {
const trainee = {
name: "Ali",
age: 33,
subjects: ["JavaScript", "React", "CSS"],
};
expect(formatCourseworkResult(trainee)).toBe(
"Error: Coursework percent is not a number!"
);
});

test("formatCourseworkResult should return 'Error: No trainee name!' for a trainee without name property", () => {
const trainee = {
score: 90,
age: 29,
};
expect(formatCourseworkResult(trainee)).toBe("Error: No trainee name!");
});

test("formatCourseworkResult should return correct string for a trainee with name 'Aman'", () => {
const trainee = {
name: "Aman",
subjects: ["HTML", "CSS", "Databases"],
score: 30
};
expect(formatCourseworkResult(trainee)).toBe("Aman's coursework was marked as grade E.");
});