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
14 changes: 7 additions & 7 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
*/

let dog = {
breed: "Dalmatian",
name: "Spot",
isHungry: true,
happiness: 6
breed: "Dalmatian",//string
name: "Spot",//string
isHungry: true,//Boolean
happiness: 6//number
};

/*
You can access the values of each property using dot notation.
You can access the values of each property using dot notation.
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}`);

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: 3 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,9 @@ let basketballTeam = {
*/

// write code here

let topPlayers = ["Michael Jordan", "Scottie Pippen", "Dennis Rodman"];
topPlayers.sort();
console.log(topPlayers);

/* EXPECTED RESULT

Expand Down
36 changes: 35 additions & 1 deletion 2-mandatory/1-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,38 @@
You should write and log at least 5 recipes
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The recipe objects look good 👍
But take another look at the instructions on lines 13-20. It looks each recipe should be output in this way:

  Mole
  Serves: 2
  Ingredients:
  cinnamon
  cumin
  cocoa

// write code here
// write code here
let receipe1= {
title: "Momo",
serving: 2,
ingredients: ["wheat", "kima", "wrapper"],
};
console.log(receipe1)

let receipe2 = {
title: "waiwai",
serving: 1,
ingredients: ["waiwai", "water", "masala"],
};
console.log(receipe2);

let receipe3 = {
title: "Omelette",
serving: 2,
ingredients: ["onion", "corrinder", "salt"],
};
console.log(receipe3);

let receipe4 = {
title: "chickencurry",
serving: 4,
ingredients: ["oil","onion","garlic", "ginger", "cumin", "corrinder", "tumeric"]
}
console.log(receipe4);

let receipe5 = {
title: "pilourice",
serving: 5,
ingredients: ["rice", "cinamom", "cumin", "onion","cloves", "bayleaves", "water"],
};
console.log(receipe5);
16 changes: 14 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@ const COUNTRY_CURRENCY_CODES = [
["MX", "MXN"],
];



function createLookup(countryCurrencyCodes) {
// write code here
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice 👍

let countryCurrencyCodesLookUp = {};

for(let countryCurrencyCode of countryCurrencyCodes){
countryCurrencyCodesLookUp[countryCurrencyCode[0]]=countryCurrencyCode[1];

}

return countryCurrencyCodesLookUp;
};




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

function createShoppingList(recipe) {
// write code here
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks good to me 👍
As an extra challenge, can you re-write this using the filter array method?

let shoppingList = {};
shoppingList.items =[];
shoppingList.name = recipe.name
// check ungredients
for (let ingredient of recipe.ingredients)
{

if (pantry.fridgeContents.includes(ingredient)=== false
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When you see something like this: pantry.fridgeContents.includes(ingredient) === false - you can re-write it like this: !pantry.fridgeContents.includes(ingredient). Can you think of why that works?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok great thank you

&& pantry.cupboardContents.includes(ingredient)=== false) {

shoppingList.items.push(ingredient);

}
}
return shoppingList;
};




/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 3-shopping-list.js`
Expand All @@ -43,11 +60,11 @@ test("createShoppingList works for pancakes recipe", () => {
test("createShoppingList works for margherita pizza recipe", () => {
let recipe2 = {
name: "margherita pizza",
ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella"],
ingredients: ["flour", "salt", "yeast", "tinned tomatoes", "oregano", "mozarella" ],
};

expect(createShoppingList(recipe2)).toEqual({
name: "margherita pizza",
items: ["flour", "yeast", "mozarella"]
});
});
});
40 changes: 38 additions & 2 deletions 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,44 @@ const MENU = {
};

let cashRegister = {
// write code here
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good 👍

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;
}
}
};

// let coffeeMachine = {
// brand: "Super Coffee",
// prices: {
// cappuccino: 2.4,
// blackCoffee: 1.5,
// flatWhite: 3.0,
// },
// insertedAmount: 0,
// insertMoney: function (amount) {
// this.insertedAmount += amount; // or this.insertedAmount = this.insertedAmount + amount;
// },
// getCoffee: function (coffee) {
// if (this.insertedAmount >= this.prices[coffee]) {
// this.insertedAmount = 0; // insertedAmount resets after a transaction
// return `Please take your ${coffee}`;
// } else {
// return `Sorry you don't have enough money for a ${coffee}`;
// }
// },




/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 4-restaurant.js`
Expand Down
47 changes: 32 additions & 15 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,59 @@ 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)).toEqual ("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. */


// * Remove the .skip above, then write the test body. *
test("a score of 71 is grade B", () => {
expect(convertScoreToGrade(71)).toEqual ("B");

});
/*
Write a test that checks a score of 68 is grade C
*/


// Write a test that checks a score of 68 is grade C
test("a score of 68 is grade C", () => {
expect(convertScoreToGrade(68)).toEqual ("C");

});
/*
Write a test that checks a score of 55 is grade D
*/

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

/*
Write a test that checks a score of 55 is grade D
*/

Copy link
Copy Markdown

@moneyinthesky moneyinthesky Mar 31, 2023

Choose a reason for hiding this comment

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

The tests above look good.
But below - it looks like you are missing toEqual?

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

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

/*
Write a test that checks a score of 70 is grade B
*/
*/test("a score of 70 is grade B", () => {
expect(convertScoreToGrade(70)), ("B");
})
36 changes: 30 additions & 6 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 @@ -54,25 +54,39 @@ function formatCourseworkResult(trainee) {
name: "Xin",
score: 63
}
*/

/*
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These are great, well done!
Good test names as well 😄

*/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", () => {
let 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:
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
{
name: "Ali",
score: 49,
age: 33,
subjects: ["JavaScript", "React", "CSS"]
}
*/
test("a score of 49 is grade E", () => {
let 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:
Expand All @@ -81,6 +95,11 @@ function formatCourseworkResult(trainee) {
age: 29
}
*/
test("object without name will fail error", () => {
let trainee = {score: 90, age: 20};
expect(formatCourseworkResult(trainee)). toEqual("Error: No trainee name!")

});

/*
Write a test that checks the output of formatCourseworkResult when passed the following trainee:
Expand All @@ -89,3 +108,8 @@ function formatCourseworkResult(trainee) {
subjects: ["HTML", "CSS", "Databases"]
}
*/
test("object without score is not a number", () => {
let trainee ={name: "Aman", subjects:["HTML", "CSS", "Databases"]};
expect(formatCourseworkResult(trainee)). toEqual("Error: Coursework percent is not a number!");

});