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
8 changes: 4 additions & 4 deletions 1-exercises/A-accessing-values/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ let dog = {
breed: "Dalmatian",
name: "Spot",
isHungry: true,
happiness: 6
happiness: 6,
};

/*
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; // complete the code
let dogBreed = dog.breed; // complete the code

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

/* EXPECTED RESULT

Spot is a Dalmatian

*/
*/
6 changes: 3 additions & 3 deletions 1-exercises/A-accessing-values/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let capitalCities = {
UnitedKingdom: "London",
China: "Beijing",
Peru: "Lima"
Peru: "Lima",
};

/*
Expand All @@ -17,12 +17,12 @@ let capitalCities = {
*/

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

console.log(myCapitalCity);

/* EXPECTED RESULT

London

*/
*/
8 changes: 5 additions & 3 deletions 1-exercises/A-accessing-values/exercise3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ let basketballTeam = {
- sorts the top players in alphabetical order
- console.logs the name of each player on a new line
*/

topGuyList = basketballTeam.topPlayers.sort();
for (let i = 0; i < topGuyList.length; i++) {
console.log(topGuyList[i]);
}
// write code here


/* EXPECTED RESULT

Dennis Rodman
Michael Jordan
Scottie Pippen

*/
*/
8 changes: 6 additions & 2 deletions 1-exercises/C-undefined-properties/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@ let car = {
};

console.log(car["colour"]);
//car does not have an attribute of colour - I would spell it color to match the other American spellings used

// Example 2
function sayHelloToUser(user) {
console.log(`Hello ${user.firstName}`);
}

let user = {
name: "Mira"
name: "Mira",
};

//No attribute of firstName

sayHelloToUser(user);

// Example 3
let myPet = {
animal: "Cat",
getName: function() {
getName: function () {
"My pet's name is Fluffy";
},
};

console.log(myPet.getName());
//The return key word has not been added to the method getName
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 @@ -9,12 +9,15 @@

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

student.getName("Daniel");

/* EXPECTED RESULT

Student name: Daniel

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

// write code here
// write code here
let banoffee = {
title:"Banoffee",
servings: 7 ,
ingredients: ["bananas","biscuits","butter","condensed milk","sugar","cream"]


}

console.log(banoffee.title)
console.log("Serves: " + banoffee.servings)
console.log("Ingredients:")

for (let i = 0; i<banoffee.ingredients.length;i++){
console.log(banoffee.ingredients[i])
}

14 changes: 12 additions & 2 deletions 2-mandatory/2-currency-code-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ const COUNTRY_CURRENCY_CODES = [
["MX", "MXN"],
];

function createLookup(countryCurrencyCodes) {
function createLookup(COUNTRY_CURRENCY_CODES) {
// write code here
const lookup = {};

for (let i = 0; i < COUNTRY_CURRENCY_CODES.length; i++) {
const country = COUNTRY_CURRENCY_CODES[i][0];
const currency = COUNTRY_CURRENCY_CODES[i][1];

lookup[country] = currency;
}

return lookup;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand All @@ -34,4 +44,4 @@ test("creates country currency code lookup", () => {
NG: "NGN",
MX: "MXN",
});
});
});
53 changes: 49 additions & 4 deletions 2-mandatory/3-shopping-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,47 @@ let pantry = {
};

function createShoppingList(recipe) {
// write code here
let missingIngredients = recipe.ingredients.filter(function (ingredient) {
return (
!pantry.fridgeContents.includes(ingredient) &&
!pantry.cupboardContents.includes(ingredient)
);
});
return {
name: recipe.name,
items: missingIngredients,
};
}

/*
function createShoppingList(recipe) {
let missingIngredients = recipe.ingredients.filter(function(ingredient) {
return !pantry.fridgeContents.includes(ingredient) && !pantry.cupboardContents.includes(ingredient);
});
return {
name: recipe.name,
items: missingIngredients
};
}

//Test this on JSFiddle

let pizzaRecipe = {
name: "Pizza",
ingredients: ["dough", "cheese", "tomato sauce"]
};

let shoppingList = createShoppingList(pizzaRecipe);
console.log(shoppingList);

// Output: { name: "Pizza", items: ["dough", "cheese"] }





*/

/* ======= 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 All @@ -43,11 +81,18 @@ 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"]
items: ["flour", "yeast", "mozarella"],
});
});
});
22 changes: 21 additions & 1 deletion 2-mandatory/4-restaurant.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@
const MENU = {
burger: 6.5,
falafel: 7.25,
};

}
;

let cashRegister = {
// write code here
orderBurger: function(balance){
if(balance<6.5){
return "You do not have enough money"
}
else if (balance >= 6.5) {
let newBalance = balance - 6.5
return newBalance
}
},

orderFalafel: function(balance){
if(balance<7.25){
return "You do not have enough money"
}
else if (balance >= 7.25) {
let newBalance = balance - 7.25
return newBalance
}
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
25 changes: 22 additions & 3 deletions 2-mandatory/5-writing-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function convertScoreToGrade(score) {
passes.
*/
test("a score of 83 is grade A", () => {
expect(convertScoreToGrade(83), "Z");
expect(convertScoreToGrade(83), "A");
});

/*
Expand All @@ -49,27 +49,46 @@ test.skip("a score of 71 is grade B", () => {
/*
Write a test that checks a score of 68 is grade C
*/

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

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

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

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(55), "");
});

/*
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), "D");
});
Loading