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
17 changes: 15 additions & 2 deletions mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,33 @@ Exercise 1:

"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/

for (let x = 0; x < writers.length; x++){
console.log(`Hi, my name is ${writers[x].firstName} ${writers[x].lastName}. I am ${writers[x].age} years old, and work as a ${writers[x].occupation}.`);
}
/*
Exercise 2:

Only `console.log()` out the writers who are in their 40s (meaning between 40 and 49)
and not alive anymore. Use the below sentence format:

"Writer {firstName} {lastName} died at {age} years old."
*/

writers.forEach((el) => {
if (el.alive === false && el.age <= 49 && el.age >= 40) {
console.log(`Writer ${el.firstName} ${el.lastName} died at ${el.age} years old.`)
}
})

/*
Exercise 3:

Only `console.log()` out alive writers who are in their 40s (meaning between 40 and 49):

"Hi, my name is {firstName} {lastName}. I am {age} years old."
*/

writers.forEach((el) => {
if (el.alive === true && el.age >= 40 && el.age <= 49) {
console.log(`Hi, my name is ${el.firstName} ${el.lastName}. I am ${el.age} years old.`)
}
})
35 changes: 34 additions & 1 deletion mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,51 @@ let bottle = {
volume: 0,
fillUp: function () {
// calling this function should completely fill your bottle (volume = 100);
return this.volume = 100;
},


pour: function () {
// calling this function should increase your bottle volume by 10 units;
if (this.volume <= 90) {
return this.volume += 10;
}
else {
return this.volume;
}
},


drink: function () {
// calling this function should decrease your bottle volume by 10 units;
if (this.volume >= 10) {
return this.volume -= 10;
}
else {
return this.volume;
}
},


isFull: function () {
// this function should return true if your bottle is full;
if (this.volume === 100) {
return true;
}
else {
return false;
}
},


isEmpty: function () {
// this function should return true if your bottle is empty;
if (this.volume === 0) {
return true;
}
else {
return false;
}
},
};

Expand All @@ -51,7 +84,7 @@ Extra question:
Leave your answer below:
*/

// Write you answer to the question here
//"This" can be used for any function even if it is not a method of an object, its value is evaluated at call-time and does not depend on where the method was declared, but rather on what object is “before the dot" and a function can be copied between objects.//

/*
Once you have completed your object run the following
Expand Down
15 changes: 13 additions & 2 deletions mandatory/3-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ Exercise 1:
Then use console.log() to print out the list.
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];
let weeklyGroceriesToBuy = []
for (let key in weeklyMealPlan) {
weeklyGroceriesToBuy.push(weeklyMealPlan[key]);
}
console.log(weeklyGroceriesToBuy);

/*
Exercise 2:
Loop through your list again, but now only collect the weekend items into the weekendGroceriesToBuy array.
Then use console.log() to print out the list.
*/
// Gather weekend item names into this array
let weekendGroceriesToBuy = [];
let weekendGroceriesToBuy = Object.values(weeklyMealPlan["saturday"]);
console.log(weekendGroceriesToBuy.length);

/*
Exercise 3:
Expand All @@ -56,3 +61,9 @@ let numberOfItemsPerWeek = {
saturday: 0,
sunday: 0,
};

for (let prop in weeklyMealPlan) {
numberOfItemsPerWeek[prop] = (weeklyMealPlan[prop].length)
}

console.log(numberOfItemsPerWeek)
32 changes: 29 additions & 3 deletions mandatory/4-people-I-know.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ First, I want you to find all of my friends who are 35 or older.
*/

let thirtyFiveOrOlder = [];
for (let y = 0; y < people.length; y++){
if (people[y].age >= 35) {
thirtyFiveOrOlder.push(people[y].name['first']);
};
}

/*
3) Find the email address
Expand All @@ -396,10 +401,16 @@ Next, I want you to find all of the people who work for "POWERNET" and then stor
*/

let powerNetEmails = [];
for (let x = 0; x < people.length; x++){
if (people[x].company === "POWERNET"){
powerNetEmails.push(people[x].email);
};
powerNetEmails.sort();
}

/*

3) Friends with "Stacie Villarreal"
4) Friends with "Stacie Villarreal"

Next, I want you to find all of my friends who are friends with Stacie Villarreal.

Expand All @@ -409,11 +420,15 @@ This time, I only want the full names of the people are who friends with her.

*/

let friendsWithStacie = [];
let friendsWithStacie = people.filter((person) =>
person.friends.some((friendName) => friendName.name.includes("Stacie Villarreal"))).map((person) =>
`${person.name.first} ${person.name.last}`)
.reverse();


/*

4) Find "Multi-tasking" friends
5) Find "Multi-tasking" friends

Next, I want you to find all of my friends of friends who are good at "Multi-tasking"

Expand All @@ -425,6 +440,17 @@ This time, I only want the full names of the people who can multitask

let friendsWhoCanMultitask = [];

for (let a = 0; a < people.length; a++){
for (let b = 0; b < people[a].friends.length; b++) {
if (people[a].friends[b].skills.includes("Multi-tasking")) {
friendsWhoCanMultitask.push(`${people[a].friends[b].name}`);
}
}
}



const { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require("constants");
/*
==================================================
====== TESTS - DO NOT MODIFY BELOW THIS LINE =====
Expand Down
38 changes: 37 additions & 1 deletion mandatory/5-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,40 @@ You should write and log at least 5 recipes

**/

let recipes = {};
let recipes = [
{
recipeName: "Noodle Soup",
recipeServings: 1-4,
recipeIngredients: ["1-4 Packs of Noodles", "Pre-made Stock(Any flavour)", "Onions", "Carrots", "Garlic", "Soup Mix", "Peri-Peri(Optional)", "Crushed Chilli(Optional)", "Milk", "Water"]
},

{
recipeName: "Cheesy Fried Onion Rings",
recipeServings: 4,
recipeIngredients: ["Onion", "Cheese(Anything that's easy to slice)", "Breadcrumbs", "Eggs", "Milk"]
},

{
recipeName: "Chocolate Peanut Butter Smoothie",
recipeServings: 4,
recipeIngredients: ["Peanut Butter", "Milk", "Honey", "Chocolate(Any Flavour)", "Crushed Peanuts", "Almonds and/or Cashew Nuts(Optional)", "Any Fruit of your choice"]
},
{
recipeName: "Chocolate Cake",
recipeServings: 12,
recipeIngredients: ["Flour", "Cake Mix", "Eggs", "Oil", "Butter", "Vanilla Essence", "Finely Chopped Chocolate"]
},

{
recipeName: "Coleslaw",
recipeServings: 8,
recipeIngredients: ["Carrots", "Raisins", "Cabbage(Green or Red)", "Red Apple", "Mayonnaise", "Salt", "Pepper", "Vinegar"]
}
];


for (recipe of recipes){
console.log(recipe.recipeName);
console.log(`Serves: ${recipe.recipeServings}`);
console.log(`Ingredients: ${recipe.recipeIngredients}\n`);
}
45 changes: 42 additions & 3 deletions mandatory/6-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,48 @@ Exercise 2
=====
Now use an if/else statement to change the output depending on whether you have read it yet or not.

If you've read it, log a string like 'You've already read "The Hobbit" by J.R.R. Tolkien',
and if not, log a string like 'You still need to read "The Lord of the Rings" by J.R.R. Tolkien.'
If you've read it, log a string like 'You've already read "The Hobbit" by J.R.R. Tolkien', True
and if not, log a string like 'You still need to read "The Lord of the Rings" by J.R.R. Tolkien.' False

**/

let books = [];
let books = [
{
bookTitle: "To Kill a MockingBird",
bookAuthor: "Harper Lee",
haveRead: true,
},

{
bookTitle: "Lord of the Flies",
bookAuthor: "William Golding",
haveRead: true,
},

{
bookTitle: "Skulduggery Pleasant Novels",
bookAuthor: "Derek Landy",
haveRead: false,
},

{
bookTitle: "Pride and Prejudice",
bookAuthor: "Jane Austen",
haveRead: false,
},

{
bookTitle: "Animal Farm",
bookAuthor: "George Orwell",
haveRead: false,
}
];

for (book of books){
if (book.haveRead === true) {
console.log(`You've already read ${book.bookTitle} by ${book.bookAuthor}`);
}
else {
console.log(`You still need to read ${book.bookTitle} by ${book.bookAuthor}`);
}
}
8 changes: 7 additions & 1 deletion mandatory/7-budgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ Should give return the answer of 62600.

**/

function getBudgets(peopleArray) {}
function getBudgets(peopleArray) {
let budgetTotal = 0;
for (person of peopleArray){
budgetTotal += person.budget;
}
return budgetTotal
}

/*
==================================================
Expand Down
10 changes: 10 additions & 0 deletions mandatory/8-cheap-diner.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ Should give the answer "Nothing :("

function chooseMeal(mealArray) {
// Write your code here
mealArray.sort((x, y) => x.price - y.price);
if (mealArray.length === 0){
return "Nothing :(";
}
else if (mealArray.length === 1){
return mealArray[0].name
}
else if(mealArray.length >= 2) {
return mealArray[1].name
}
}

/*
Expand Down