Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Closed
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
13 changes: 11 additions & 2 deletions mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Exercise 1:
"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/
function logAllWriters() {
writers.forEach((writer) => console.log (`Hi, my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old, and work as a ${writer.occupation}.`));
// write your code to log all writers here
};

Expand All @@ -80,7 +81,11 @@ Exercise 2:
*/

function logDeadWritersInTheirForties() {
// write your code here
writers.forEach ((writer) => {
if (writer.age>=40 && writer.age <=49 && writer.alive === false){
console.log(`Writer ${writer.firstName} ${writer.lastName} died at ${writer.age} years old.`);// write your code here
}
})
}

/*
Expand All @@ -92,7 +97,11 @@ Exercise 3:
*/

function logAliveWritersInTheirForties() {
// write your code here
writers.forEach((writer) => {
if(writer.age >=40 && writer.age < 50 && writer.alive) {
console.log(`Hi, my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old.`);
}
})
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
3 changes: 2 additions & 1 deletion mandatory/2-eligible-students.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/

function eligibleStudents(attendances) {

const studentsAttended = attendances.filter(student => student.attendance >= 8).map(student => student.name)
return studentsAttended;
}

/* ======= TESTS - DO NOT MODIFY =====
Expand Down
16 changes: 13 additions & 3 deletions mandatory/4-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ You have to implement the missing features according to the specification.
let bottle = {
volume: 0,
fillUp: function () {
this.volume = 100;
// calling this function should completely fill your bottle (volume = 100);
},
pour: function () {
if (this.volume <= 90) this.volume += 10;
// calling this function should increase your bottle volume by 10 units;
},

},

drink: function () {
if(this.volume >= 10) this.volume -=10;
else if (this.volume < 10) this.volume = 0;


// calling this function should decrease your bottle volume by 10 units;
},
isFull: function () {
this.volume === 100;
// this function should return true if your bottle is full;
},
isEmpty: function () {
return this.volume === 0
// this function should return true if your bottle is empty;
},
};
}
};

/*
TIP:
Expand Down
13 changes: 9 additions & 4 deletions mandatory/5-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ Exercise 1:
The weeklyGroceriesToBuy array shouldn't contain any repeating items.
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];

let weeklyGroceriesToBuy = [ ];
const Items = Object.values(weeklyMealPlan).flat();
Items.forEach((food) => {
if (!weeklyGroceriesToBuy.includes(food)) weeklyGroceriesToBuy.push(food);
})
/*
Exercise 2:
Loop through your list again, but now only collect the weekend items into the weekendGroceriesToBuy array.
*/
// Gather weekend item names into this array
let weekendGroceriesToBuy = [];

let weekendGroceriesToBuy = Object.values(weeklyMealPlan.saturday).concat(Object.values(weeklyMealPlan.sunday));
/*
Exercise 3:
Loop through your weekly meal plan:
Expand All @@ -54,6 +56,9 @@ let numberOfItemsPerWeek = {
sunday: 0,
};

for (const key in weeklyMealPlan){
numberOfItemsPerWeek[key] = weeklyMealPlan[key].length;
}
/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 5-groceries.js`
- To run all exercises/tests in the mandatory folder, run `npm test`
Expand Down
13 changes: 12 additions & 1 deletion mandatory/6-people-I-know.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ First, I want you to find all of my friends who are 35 or older.
*/

let thirtyFiveOrOlder = [];

thirtyFiveOrOlder = friends.filter((friend) => friend.age >=35);
/*
3) Find the email address

Expand All @@ -392,6 +392,7 @@ Next, I want you to find all of my friends who work for "POWERNET" and then stor
*/

let powerNetEmails = [];
powerNetEmails = friends.filter (friend => friend.company === "POWERNET").map(friend => friend.email);

/*

Expand All @@ -406,6 +407,11 @@ This time, I only want the full names ("<firstname> <lastname>") of my friends w
*/

let friendsWhoAreColleaguesOfStacie = [];
friends.forEach((friend) => {
friend.colleagues.forEach((colleague) => {
if (colleague.name === "Stacie Villreal") friendsWhoAreColleaguesOfStacie.push(`${friend.name.first} ${friend.name.last}`);
});
});
/*

5) Find "Multi-tasking" colleagues
Expand All @@ -419,6 +425,11 @@ This time, I only want the full names of the people who can multitask
*/

let colleaguesWhoCanMultitask = [];
friends.forEach ((friend) => {
friend.colleagues.forEach ((colleague) => {
if (colleague.skills.includes("Multi-tasking")) colleaguesWhoCanMultitask.push(colleague.name);
});
});

/* ======= TESTS - DO NOT MODIFY =====
- To run the tests for this exercise, run `npm test -- --testPathPattern 6-people-I-know.js`
Expand Down
42 changes: 41 additions & 1 deletion mandatory/7-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,45 @@ You should write and log at least 5 recipes

**/

let recipes = {};


let recipes = {
recipeOne: {
title: "Curry",
serves: 2,
ingredients: ["rice", "meat", "sauce"]
},

recipeTwo: {
title: "Fajitas",
serves: 4,
ingredients: ["chicken", "wraps", "spices"]
},

recipeThree: {
title: " Fried Rice",
serves: 2,
ingredients: ["rice", "egg", "veg"]
},

recipeFour: {
title: "tiramisu",
serves: 10,
ingredients: ["coffee", "cream", "sponge fingers"]
},

recipeFive: {
title: "Pizza",
serves: 1,
ingredients: ["flour", "water", "yeast", "tomato", "mozarella"]
}
};


for (const recipe in recipes) {
console.log(`title: ${recipes[recipe].title}`);
console.log(`serves: ${recipes[recipe].serves}`);
recipes[recipe].ingredients.map((ingredient) => {
console.log(ingredient)
})
};
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@


{
"name": "javascript-core-2-coursework-week1",
"version": "1.0.0",
"description": "Exercises for JS2 Week 1",
"scripts": {
"test": "jest --testRegex='mandatory[/\\\\].*\\.js$' --testPathIgnorePatterns='choose-your-own|recipes|water-bottle'"
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -16,6 +18,15 @@
"setupFilesAfterEnv": [
"jest-extended",
"./.setup/jest.setup.js"
],
"testPathIgnorePatterns": [
"<rootDir>/mandatory/choose-your-own",
"<rootDir>/mandatory/recipes",
"<rootDir>/mandatory/water-bottle",
"<rootDir>/node_modules/"
],
"testRegex": [
"mandatory[/\\\\].*\\.js$"
]
},
"homepage": "https://github.com/CodeYourFuture/JavaScript-Core-2-Coursework-Week1#readme",
Expand All @@ -24,4 +35,4 @@
"jest-extended": "^0.11.5"
},
"licence": "CC-BY-4.0"
}
}