From 9e4a82df1495c411e3c6c4db33faa4269f1a9428 Mon Sep 17 00:00:00 2001 From: kaniwar103 Date: Sat, 24 Nov 2018 21:25:23 +0100 Subject: [PATCH 1/2] js2 homework week2 --- Week2/homework/maartjes_work.js | 15 +++++++++++++++ Week2/homework/map_filter.js | 7 +++++++ package-lock.json | 3 +++ 3 files changed, 25 insertions(+) create mode 100644 package-lock.json diff --git a/Week2/homework/maartjes_work.js b/Week2/homework/maartjes_work.js index 0b451d122..cf0946aa4 100644 --- a/Week2/homework/maartjes_work.js +++ b/Week2/homework/maartjes_work.js @@ -45,3 +45,18 @@ const tuesday = [ const tasks = monday.concat(tuesday); // Add your code here +// Map the tasks to durations in hours. +const hours = tasks.map(function(taskHour){ + return taskHour.duration / 60; +}) +console.log(hours);//[ 3,2,0.33,3.33,4,3,0.16,3.33,0.66 ] + +// Filter out everything that took less than two hours +const earningHours = hours.filter(function(earningHour){ +return earningHour >= 2; +}) +console.log(earningHours);//[ 3, 2, 3.33, 4, 3, 3.33 ] + +// Multiply the duration per-hour rate and sum it all up. +const totalEarning = earningHours.map(hours => hours * 9) +.reduce((money, payment) => money + payment); diff --git a/Week2/homework/map_filter.js b/Week2/homework/map_filter.js index b6af22631..255aff54b 100644 --- a/Week2/homework/map_filter.js +++ b/Week2/homework/map_filter.js @@ -3,3 +3,10 @@ const numbers = [1, 2, 3, 4]; // Add your code here +const numbers = [1, 2, 3, 4]; +const newNumbers = numbers.filter(function(number){ + return (number % 2 !== 0); +}).map(function(number){ + return number * 2; +}); +console.log("The doubled numbers are", newNumbers); // [2, 6] diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..48e341a09 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} From e05c5427c5d9c9414c6f2e756bff0d1d25e70289 Mon Sep 17 00:00:00 2001 From: kaniwar103 Date: Sat, 24 Nov 2018 21:56:11 +0100 Subject: [PATCH 2/2] js2 homework week1 --- Week1/homework/app.js | 98 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/Week1/homework/app.js b/Week1/homework/app.js index ffef836dc..0a59abed9 100644 --- a/Week1/homework/app.js +++ b/Week1/homework/app.js @@ -2,10 +2,104 @@ { const bookTitles = [ // Replace with your own book titles - 'harry_potter_chamber_secrets' + "the_vegetarian", "watership_down", + + "adventures_sherlock_holmes", "alchemist", + + "frankenstein", "city_of_thieves", "gone_with_the_wind", + + "kill_a_mockingbird", "war_and_peace", "things_fall_apart" ]; // Replace with your own code - console.log(bookTitles); + + const booksDetails = { + + the_vegetarian : {title: "The Vegetarian", lang: "English", author: "Han Kang"}, + + watership_down : {title: "Watership Down", lang: "English", author: "Richard Adams"}, + + adventures_sherlock_holmes : {title: "The Adventures of Sherlock Holmes", lang: "English", author: "Arthur Conan Doyle"}, + + alchemist : {title: "Alchemist", lang: "English", author: "Paulo Coelho"}, + + frankenstein : {title: "Frankenstein", lang: "English", author: "Mary Shelley"}, + + city_of_thieves : {title: "City of Thieves", lang: "English", author:"David Benioff"}, + + gone_with_the_wind : {title: "Gone With the Wind", lang: "English", author: "Margaret Mitchell"}, + + kill_a_mockingbird : {title: "To Kill A Mockingbird", lang: "English", author: "Harper Lee"}, + + war_and_peace : {title: "War and Peace", lang: "English", author: "Leo Tolstoy"}, + + things_fall_apart : {title: "Things Fall Apart", lang: "English", author: "Chinua Achebe"} + +}; + +const bookCovers = { + the_vegetarian : "https://static.abebookscdn.com/cdn/com/images/100-books/Vegetarian,%20The.jpg" , + watership_down : "https://static.abebookscdn.com/cdn/com/images/100-books/Watership%20Down.jpg", + adventures_sherlock_holmes : "https://static.abebookscdn.com/cdn/com/images/100-books/Adventures%20of%20Sherlock%20Holmes.jpg", + alchemist : "https://static.abebookscdn.com/cdn/com/images/100-books/Alchemist.jpg", + frankenstein : "https://static.abebookscdn.com/cdn/com/images/100-books/Frankenstein.jpg", + city_of_thieves : "https://static.abebookscdn.com/cdn/com/images/100-books/City%20of%20Thieves.jpg", + gone_with_the_wind : "https://static.abebookscdn.com/cdn/com/images/100-books/Gone%20With%20the%20Wind.jpg", + kill_a_mockingbird : "https://static.abebookscdn.com/cdn/com/images/100-books/To%20Kill%20a%20Mockingbird.jpg", + war_and_peace : "https://static.abebookscdn.com/cdn/com/images/100-books/War%20and%20Peace.jpg", + things_fall_apart : "https://static.abebookscdn.com/cdn/com/images/100-books/Things%20Fall%20Apart.jpg", +}; +} + +function generateList() { + const newList = document.createElement('ul'); + document.body.appendChild(generateList); + for (let i = 0; i < bookTitles.length; i++) { + const list = document.createElement("li"); + newList.appendChild(li); + newList.innerHTML = (bookTitles)[i]; + const bookImages = document.createElement("img"); + li.appendchild(bookImages); + li.setAttribute("id", Object.keys(bookCovers)[i]); + + const para = document.createElement("p"); + li.appendChild(para); + p.innerHTML = ("lang :" + (Object.values(booksDetails)[i]).lang); + + const para1 = document.createElement("p"); + li.appendChild(para1); + p1.innerHTML = ("lang : " + (Object.values(booksDetails)[i]).author); + + } + + return newList; + + } + + console.log(newList); + + +// const head1 = document.createElement("h1"); +// Li.appenChild(head1); + +// h1.innerHTML = (Object.values(booksDetails)[i]).title; + +// const bookImages = document.createElement("img"); +// li.appendchild(bookImages); +// li.setAttribute("id", Object.keys(bookCovers)[i]); + +// const para = document.createElement("p"); + +// li.appendChild(para); + +// p.innerHTML = ("lang :" + (Object.values(booksDetails)[i]).lang); + +// const para1 = document.createElement("p"); + +// li.appendChild(para1); + +// p1.innerHTML = ("lang : " + (Object.values(booksDetails)[i]).author); + +// console.log(newList); }