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
10 changes: 5 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ London Class 7 - Chris Owen - HTML/CSS - Week 1

# Your Details

- Your Name:
- Your City:
- Your Slack Name:
- Your Name: Kara Howard
- Your City: London
- Your Slack Name: Kara Howard

# Homework Details

- Module:
- Week:
- Module: JavaScript Core 2
- Week: 1
14 changes: 13 additions & 1 deletion mandatory/1-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Exercise 1:

"Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}."
*/
writers.forEach(function (writers) {
console.log(`Hi, my name is ${writers.firstName} ${writers.lastName}. I am ${writers.age} years old, and work as a ${writers.occupation}.`);
});

/*
Exercise 2:
Expand All @@ -68,11 +71,20 @@ Exercise 2:

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

writers.forEach(function (writers) {
if (writers.age > 40 && writers.age < 49 && writers.alive === false) {
console.log(`Writer ${writers.firstName} ${writers.lastName} died at ${writers.age} years old.`);
}
});
Comment on lines +74 to +78
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done for using the forEach method and JavaScript string interpolation!

A couple of suggestions for small improvements:

  • Variable naming: the parameter writers of the anonymous function (that is, the function without a name that you're passing to the forEach method) could instead be named writer, in the singular. That's because semantically you are holding the data for only one writer in that variable.
  • The logical expression in the if statement is excluding writers who are 40 years old; you can use the >= comparison operator to include them.

/*
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(function (writers) {
if (writers.age > 40 && writers.age < 49 && writers.alive === true) {
console.log(`Hi, my name is ${writers.firstName} ${writers.lastName}. I am ${writers.age} years old.`);
}
});
11 changes: 10 additions & 1 deletion mandatory/2-water-bottle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ 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;
}
},
drink: function () {
// calling this function should decrease your bottle volume by 10 units;
if (this.volume >= 10) {
return this.volume -= 10;
}
},
isFull: function () {
// this function should return true if your bottle is full;
return this.volume === 100;
},
isEmpty: function () {
// this function should return true if your bottle is empty;
},
return this.volume === 0;
}
};

/*
Expand Down
16 changes: 14 additions & 2 deletions mandatory/3-groceries.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,22 @@ Exercise 1:
*/
// Gather all week item names into this array
let weeklyGroceriesToBuy = [];
for (day in weeklyMealPlan) {
weeklyGroceriesToBuy = weeklyGroceriesToBuy.concat(weeklyMealPlan[day]);
}
weeklyGroceriesToBuy = weeklyGroceriesToBuy.filter(function(ingredient, index, array) {
return index === array.indexOf(ingredient);
})
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 = weeklyMealPlan.saturday.concat(weeklyMealPlan.sunday);
console.log(weekendGroceriesToBuy);
/*
Exercise 3:
Loop through your weekly meal plan:
Expand All @@ -56,3 +63,8 @@ let numberOfItemsPerWeek = {
saturday: 0,
sunday: 0,
};

for (key in weeklyMealPlan) {
numberOfItemsPerWeek[key] = weeklyMealPlan[key].length
}
console.log(numberOfItemsPerWeek);
21 changes: 17 additions & 4 deletions mandatory/4-people-I-know.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ First, I want you to find all of my friends who are 35 or older.

*/

let thirtyFiveOrOlder = [];
let thirtyFiveOrOlder = people.filter((friend) => friend.age >= 35);

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

*/

let powerNetEmails = [];

let powerNetEmails = people.filter(friend => friend.company === "POWERNET")
.map(friend => friend.email)
.reverse();
/*

3) Friends with "Stacie Villarreal"
Expand All @@ -409,7 +410,12 @@ This time, I only want the full names of the people are who friends with her.

*/

let friendsWithStacie = [];
let friendsWithStacie = people
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent work here Kara, good use of higher-order functions.

.filter((person) => person.friends
.find((friend) => friend.name === "Stacie Villarreal")
)
.map((person) => `${person.name.first} ${person.name.last}`)
.reverse();

/*

Expand All @@ -424,6 +430,13 @@ This time, I only want the full names of the people who can multitask
*/

let friendsWhoCanMultitask = [];
people.map((person) => {
person.friends.map((friend) => {
if (friend.skills.includes("Multi-tasking")) {
friendsWhoCanMultitask.push(friend.name);
}
});
});

/*
==================================================
Expand Down
43 changes: 42 additions & 1 deletion mandatory/5-recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,45 @@ You should write and log at least 5 recipes

**/

let recipes = {};
let recipes = [
{
Title: "Chorizo & mozzarella gnocchi bake",
Servings: 6,
Ingredients: ["olive oil", "onion", "garlic",
"chorizo", "tomatoes", "caster sugar",
"fresh gnocchi", "mozzarella", "basil"]
},
{
Title: "Chicken fajitas",
Servings: 3,
Ingredients: ["chicken", "onion", "red pepper",
"red chilli", "paprika", "coriander",
"tortillas", "garlic", "olive oil"]
},
{
Title: "Piri-piri chicken with smashed sweet potatoes & broccoli",
Servings: 3,
Ingredients: ["chicken", "sweet potatoes", "oil",
"red onion", "piri-piri spice mix", "long-stem broccoli"]
},
{
Title: "Carrot cake",
Servings: 10,
Ingredients: ["natural yogurt", "eggs", "orange zested",
"self-raising flour", "light muscovado sugar", "cinnamon",
"nutmeg"]
},
{
Title: "Treacle sponge",
Servings: 8,
Ingredients: ["golden syrup", "lemon zest", "breadcrumb",
"butter", "golden caster sugar", "eggs",
"self-raising flour", "milk"]
}
];

for (recipe of recipes){
console.log(recipe.Title);
console.log(`Serves: ${recipe.Servings}`);
console.log(`Ingredients: ${recipe.Ingredients}\n`);
}
37 changes: 36 additions & 1 deletion mandatory/6-reading-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,39 @@ and if not, log a string like 'You still need to read "The Lord of the Rings" by

**/

let books = [];
let books = [
{
Title: "The Hobbit",
Author: "J.R.R. Tolkien",
Read: true
},
{
Title: "To Kill a Mockingbird",
Author: "Harper Lee",
Read: false
},
{
Title: "The Great Gatsby",
Author: "F. Scott Fitzgerald",
Read: false
},
{
Title: "One Hundred Years of Solitude",
Author: "Gabriel García Márquez",
Read: true
},
{
Title: "Beloved",
Author: "Toni Morrison",
Read: true
}
];

for (book of books){
if (book.Read === true){
console.log(`You've already read ${book.Title} by ${book.Author}`);
}
else {
console.log(`You still need to read ${book.Title} by ${book.Author}`);
}
}
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 sumOfBudgets = 0;
for (person of peopleArray){
sumOfBudgets += person.budget;
}
return sumOfBudgets;
}

/*
==================================================
Expand Down
13 changes: 11 additions & 2 deletions mandatory/8-cheap-diner.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ Should give the answer "Nothing :("

**/

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

/*
Expand Down