diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3756caaf..ebae1bfd 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -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 diff --git a/mandatory/1-writers.js b/mandatory/1-writers.js index d56af2fb..f6cd823e 100644 --- a/mandatory/1-writers.js +++ b/mandatory/1-writers.js @@ -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: @@ -68,7 +71,11 @@ 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.`); + } +}); /* Exercise 3: @@ -76,3 +83,8 @@ Exercise 3: "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.`); + } +}); \ No newline at end of file diff --git a/mandatory/2-water-bottle.js b/mandatory/2-water-bottle.js index d8207867..a7be40db 100644 --- a/mandatory/2-water-bottle.js +++ b/mandatory/2-water-bottle.js @@ -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; + } }; /* diff --git a/mandatory/3-groceries.js b/mandatory/3-groceries.js index 35bf3f65..ba78a690 100644 --- a/mandatory/3-groceries.js +++ b/mandatory/3-groceries.js @@ -30,6 +30,13 @@ 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: @@ -37,8 +44,8 @@ Exercise 2: 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: @@ -56,3 +63,8 @@ let numberOfItemsPerWeek = { saturday: 0, sunday: 0, }; + +for (key in weeklyMealPlan) { + numberOfItemsPerWeek[key] = weeklyMealPlan[key].length +} +console.log(numberOfItemsPerWeek); \ No newline at end of file diff --git a/mandatory/4-people-I-know.js b/mandatory/4-people-I-know.js index 2f223584..f75594c6 100644 --- a/mandatory/4-people-I-know.js +++ b/mandatory/4-people-I-know.js @@ -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 @@ -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" @@ -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 +.filter((person) => person.friends +.find((friend) => friend.name === "Stacie Villarreal") +) +.map((person) => `${person.name.first} ${person.name.last}`) +.reverse(); /* @@ -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); + } + }); +}); /* ================================================== diff --git a/mandatory/5-recipes.js b/mandatory/5-recipes.js index 4c07f439..8b5145e6 100644 --- a/mandatory/5-recipes.js +++ b/mandatory/5-recipes.js @@ -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`); +} \ No newline at end of file diff --git a/mandatory/6-reading-list.js b/mandatory/6-reading-list.js index b0b3477e..00b5c68d 100644 --- a/mandatory/6-reading-list.js +++ b/mandatory/6-reading-list.js @@ -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}`); + } +} \ No newline at end of file diff --git a/mandatory/7-budgets.js b/mandatory/7-budgets.js index 787c8433..4e92fc6f 100644 --- a/mandatory/7-budgets.js +++ b/mandatory/7-budgets.js @@ -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; +} /* ================================================== diff --git a/mandatory/8-cheap-diner.js b/mandatory/8-cheap-diner.js index a7032c5b..8095707b 100644 --- a/mandatory/8-cheap-diner.js +++ b/mandatory/8-cheap-diner.js @@ -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 + } + } } /*