diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6ad11250 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.ignoreWords": [ + "azkaban" + ] +} \ No newline at end of file diff --git a/mandatory/1-writers.js b/mandatory/1-writers.js index d56af2fb..553c6b8d 100644 --- a/mandatory/1-writers.js +++ b/mandatory/1-writers.js @@ -59,7 +59,10 @@ Exercise 1: "Hi, my name is {firstName} {lastName}. I am {age} years old, and work as a {occupation}." */ - +for (let obj of writers){ + // console.log(obj); + console.log(`Hi, my name is ${obj.firstName} ${obj.lastName}. I am ${obj.age} years old, and work as a ${obj.occupation}`); + }; /* Exercise 2: @@ -68,7 +71,13 @@ Exercise 2: "Writer {firstName} {lastName} died at {age} years old." */ - +for (let el of writers){ + // console.log(el); + let match = (el.age >= 40 && el.age <= 49 && el.alive === false); + if (match === true){ + console.log(`Writer ${el.firstName} ${el.lastName} died at ${el.age} years old.`); + } +} /* Exercise 3: @@ -76,3 +85,10 @@ Exercise 3: "Hi, my name is {firstName} {lastName}. I am {age} years old." */ +for (let item of writers){ + // console.log(item); + let match2 = (item.age >= 40 && item.age <= 49 && item.alive === true); + if(match2 === true){ + console.log(`Hi, my name is ${item.firstName} ${item.lastName}. I am ${item.age} years old.`); + } +} diff --git a/mandatory/2-water-bottle.js b/mandatory/2-water-bottle.js index d8207867..4239f299 100644 --- a/mandatory/2-water-bottle.js +++ b/mandatory/2-water-bottle.js @@ -1,5 +1,5 @@ /* -Create an object that acts a water bottle. +Create an object that acts like a water bottle. It will need a volume property to store how full or empty the bottle is. @@ -23,19 +23,33 @@ You have to implement the missing features according to the specification. let bottle = { volume: 0, fillUp: function () { - // calling this function should completely fill your bottle (volume = 100); + this.volume = 100;// calling this function should completely fill your bottle (volume = 100); }, pour: function () { - // calling this function should increase your bottle volume by 10 units; + if (this.volume <100){ + this.volume = this.volume + 10; + } else if(this.volume === 100){ + return "Bottle full"; + }// calling this function should increase your bottle volume by 10 units; }, drink: function () { - // calling this function should decrease your bottle volume by 10 units; + if(this.volume >=10){ + this.volume = this.volume - 10; + }else if(this.volume === 0){ + return "Sorry! Bottle is empty, please re-fill"; + } // calling this function should, decrease your bottle volume by 10 units; }, isFull: function () { - // this function should return true if your bottle is full; + if (this.volume === 100){ + return true; + } + return false;// this function should return true if your bottle is full; }, isEmpty: function () { - // this function should return true if your bottle is empty; + if (this.volume === 0){ + return true; + } + return false; // this function should return true if your bottle is empty; }, }; @@ -51,7 +65,7 @@ Extra question: Leave your answer below: */ -// Write you answer to the question here +// Write you answer to the question here - I think it would become confusing to refer to the object by it's name within the object, it makes code more readable as well and since the object represents a local environment it is logical. /* Once you have completed your object run the following @@ -159,7 +173,7 @@ if (bottle.isEmpty()) { } if (bottle.volume === 0) { - console.log(`That's correct! Empty bottle volume is repesented as zero.`); + console.log(`That's correct! Empty bottle volume is represented as zero.`); } else { failed = true; diff --git a/mandatory/3-groceries.js b/mandatory/3-groceries.js index 35bf3f65..a5001a77 100644 --- a/mandatory/3-groceries.js +++ b/mandatory/3-groceries.js @@ -15,7 +15,7 @@ Complete the exercises below. let weeklyMealPlan = { monday: ["Cheese", "Eggs", "Tomato", "Paprika", "Leek"], tuesday: ["Wrap", "Tuna", "Canned beans", "Cheese", "Carrot", "Aubergine"], - wednesday: ["Orange Juice", "Apple", "Ananas", "Black tea"], + wednesday: ["Orange Juice", "Apple", "Ananas", "Black tea"], thursday: ["Lamb", "Salt", "Bulgur", "Potato"], friday: ["Rice milk", "Blueberries", "Porridge", "Banana", "Cinnamon"], saturday: ["Olive oil", "Potato", "Salmon", "Asparagus"], @@ -28,9 +28,25 @@ Exercise 1: The weeklyGroceriesToBuy array shouldn't contain any repeating items. Then use console.log() to print out the list. */ -// Gather all week item names into this array let weeklyGroceriesToBuy = []; +let weeklyEntries = Object.entries(weeklyMealPlan); +// console.log(weeklyEntries); +for (let item of weeklyEntries){ + // console.log(item[1]); + item[1].filter(el =>{ + // console.log(el); + if (weeklyGroceriesToBuy.includes(el)){ + return false ; + }else { + weeklyGroceriesToBuy.push(el); + } + return weeklyGroceriesToBuy; + }); + +} +// console.log(weeklyGroceriesToBuy); // Gather all week item names into this array + /* Exercise 2: Loop through your list again, but now only collect the weekend items into the weekendGroceriesToBuy array. @@ -38,6 +54,16 @@ Exercise 2: */ // Gather weekend item names into this array let weekendGroceriesToBuy = []; + weeklyEntries.filter(el =>{ + // console.log(el); + if(el[0] === "saturday" || el[0] === "sunday"){ + weekendGroceriesToBuy.push(el[1]); + } + return weekendGroceriesToBuy; + }); + +// console.log(weekendGroceriesToBuy); + /* Exercise 3: @@ -56,3 +82,9 @@ let numberOfItemsPerWeek = { saturday: 0, sunday: 0, }; +for (let day in weeklyMealPlan){ + // console.log(weeklyMealPlan[day].length); + // console.log(numberOfItemsPerWeek[day]); + numberOfItemsPerWeek[day] = weeklyMealPlan[day].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..c06f9a1a 100644 --- a/mandatory/4-people-I-know.js +++ b/mandatory/4-people-I-know.js @@ -387,6 +387,14 @@ First, I want you to find all of my friends who are 35 or older. */ let thirtyFiveOrOlder = []; +for (let person of people){ + // console.log(person.age); + if(person.age >= 35){ + thirtyFiveOrOlder.push(person); + } +} +// console.log(thirtyFiveOrOlder); + /* 3) Find the email address @@ -396,6 +404,13 @@ Next, I want you to find all of the people who work for "POWERNET" and then stor */ let powerNetEmails = []; +for (let person of people){ + if (person.company === "POWERNET"){ + powerNetEmails.unshift(person.email); + } +} +// console.log(powerNetEmails); + /* @@ -410,6 +425,15 @@ This time, I only want the full names of the people are who friends with her. */ let friendsWithStacie = []; +for (friend of people){ + // console.log(friend); + for (item of friend.friends){ + // console.log(item.name); + if (item.name === "Stacie Villarreal"){ + friendsWithStacie.unshift(`${friend.name.first} ${friend.name.last}`); + } + } +} /* @@ -424,6 +448,15 @@ This time, I only want the full names of the people who can multitask */ let friendsWhoCanMultitask = []; +for (let object of people){ + // console.log(object.friends); + for (let arr of object.friends) + // console.log(arr.skills); + if (arr.skills.includes("Multi-tasking")){ + friendsWhoCanMultitask.push(arr.name); + } +} +// console.log(friendsWhoCanMultitask); /* ================================================== diff --git a/mandatory/5-recipes.js b/mandatory/5-recipes.js index 4c07f439..e95b8a82 100644 --- a/mandatory/5-recipes.js +++ b/mandatory/5-recipes.js @@ -3,7 +3,7 @@ The Recipe Card Never forget another recipe! -Create an object to hold information on your favorite recipe. +Create an object to hold information on your favorite recipes. It should have properties for @@ -24,4 +24,45 @@ You should write and log at least 5 recipes **/ -let recipes = {}; +let recipes = [ + { + Title: "Scrambled eggs", + Servings: 2, + Ingredients: ["eggs", "bread", "butter"] +}, + { + Title: "Boeber", + Servings: 4, + Ingredients: ["Vermicelli", "Milk", "Cinnamon", "Sugar","Sago"] +}, + { + Title: "Koesisters", + Servings: 6, + Ingredients: ["Cake Flour", "Milk", "Aniseed", "Sugar", "Baking powder","Water"] +}, +{ + Title: "Spaghetti bolognese", + Servings: 4, + Ingredients: ["Spaghetti", "Mince", "Tomato Paste", "Sugar", "Cinnamon Sticks","Black Pepper","Salt","Tomatoes","Basil","Bay leaves","Pimento"] +}, +{ + Title: "Chicken curry masala", + Servings: 4, + Ingredients: ["Skinless chicken breasts", "Onion", "Salt", "Curry powder","Bay leaves","Tumeric powder","Masala powder","Basmati rice","Tomato salad"] +}, + +]; + +let recipeCard = function (recipeArr){ +for (let recipe of recipeArr){ +console.log(recipe.Title); +console.log("Serves: ", recipe.Servings); +console.log("Ingredients: "); +recipe.Ingredients.forEach(element => { + console.log(element); +}); +console.log(" "); +} +}; + +recipeCard(recipes); \ No newline at end of file diff --git a/mandatory/6-reading-list.js b/mandatory/6-reading-list.js index b0b3477e..33b8a83c 100644 --- a/mandatory/6-reading-list.js +++ b/mandatory/6-reading-list.js @@ -23,4 +23,55 @@ and if not, log a string like 'You still need to read "The Lord of the Rings" by **/ -let books = []; +let books = [ + { + Title: "Harry Potter and the Philosopher's Stone", + Author: "J. K. Rowling", + Read: true, + }, + { + Title: "Harry Potter and the Chamber of Secrets", + Author: "J. K. Rowling", + Read: true, + }, + { + Title: "Harry Potter and the Prisoner of Azkaban", + Author: "J. K. Rowling", + Read: true, + }, + { + Title: "Harry Potter and the Goblet of Fire", + Author: "J. K. Rowling", + Read: false, + }, + { + Title: "Harry Potter and the Order of the Phoenix", + Author: "J. K. Rowling", + Read: false, + }, + { + Title: "Harry Potter and the Half-blood Prince", + Author: "J. K. Rowling", + Read: false, + }, + { + Title: "Harry Potter and the Deathly Hallows", + Author: "J. K. Rowling", + Read: false, + }, +]; + +function bookList (bookArr){ + for(let book of bookArr){ + console.log(`${book.Title} by ${book.Author}`); + if (book.Read){ + console.log(`You have read ${book.Title}`); + }else{ + console.log(`You still need to read ${book.Title}`); + } + console.log(" "); + } +}; + +bookList(books); + diff --git a/mandatory/7-budgets.js b/mandatory/7-budgets.js index 787c8433..c6ac13fe 100644 --- a/mandatory/7-budgets.js +++ b/mandatory/7-budgets.js @@ -16,7 +16,20 @@ Should give return the answer of 62600. **/ -function getBudgets(peopleArray) {} +function getBudgets(peopleArray) { + let budget = [] + if(peopleArray.length === 0){ + return 0; + } + else{ + for(let person of peopleArray){ + budget.push(person.budget); + } + } + return budget.reduce(function(accumulator,currentValue){ + return accumulator + currentValue; + }); +} /* ================================================== diff --git a/mandatory/8-cheap-diner.js b/mandatory/8-cheap-diner.js index a7032c5b..fc0da457 100644 --- a/mandatory/8-cheap-diner.js +++ b/mandatory/8-cheap-diner.js @@ -2,7 +2,7 @@ The Frugal Gentleman -Atticus has been invited to a dinner party, and he decides to purchase a meal to share with he party +Atticus has been invited to a dinner party, and he decides to purchase a meal to share with the party Being a very frugal gentleman (yet disliking looking like a cheapskate), he decides to use a very simple rule. In any selection of two or more meals, he will always buy the second-cheapest. @@ -30,7 +30,15 @@ Should give the answer "Nothing :(" **/ function chooseMeal(mealArray) { - // Write your code here + if (mealArray.length === 0 ){ + return "Nothing :("; + } else if(mealArray.length ===1){ + return mealArray[0].name; + }else if( mealArray.length >=2){ + mealArray.sort((highPrice, lowPrice)=> highPrice.price- lowPrice.price); + // console.log(mealArray); + return mealArray[1].name; + } } /*