From 9e4a82df1495c411e3c6c4db33faa4269f1a9428 Mon Sep 17 00:00:00 2001 From: kaniwar103 Date: Sat, 24 Nov 2018 21:25:23 +0100 Subject: [PATCH 1/3] 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/3] 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); } From 6703350eb6fa4baacec491a9fe586d4e751d20d8 Mon Sep 17 00:00:00 2001 From: kaniwar103 Date: Sun, 2 Dec 2018 01:08:01 +0100 Subject: [PATCH 3/3] homework week3 --- Week3/homework/1-step3.js | 1 + Week3/homework/3-step3.js | 21 ++++++++++++++++++--- Week3/homework/4-step3.js | 5 +++++ Week3/homework/5-step3.js | 8 ++++++++ Week3/homework/step4-bonus.js | 10 ++++++++-- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Week3/homework/1-step3.js b/Week3/homework/1-step3.js index bee3be0a0..f9dded925 100644 --- a/Week3/homework/1-step3.js +++ b/Week3/homework/1-step3.js @@ -2,6 +2,7 @@ function foo(func) { // What to do here? + return func } function bar() { diff --git a/Week3/homework/3-step3.js b/Week3/homework/3-step3.js index 75200818b..ea8be2f20 100644 --- a/Week3/homework/3-step3.js +++ b/Week3/homework/3-step3.js @@ -3,7 +3,11 @@ // use a 'for' loop function repeatStringNumTimesWithFor(str, num) { // add your code here - return str; + let string = ""; + for (let i = 0; i < num; i++) { + string += str; + } + return string; } console.log('for', repeatStringNumTimesWithFor('abc', 3)); @@ -11,7 +15,11 @@ console.log('for', repeatStringNumTimesWithFor('abc', 3)); // use a 'while' loop function repeatStringNumTimesWithWhile(str, num) { // add your code here - return str; + while (num > 0) { + string += str; + num--; + } + return string; } console.log('while', repeatStringNumTimesWithWhile('abc', 3)); @@ -19,7 +27,14 @@ console.log('while', repeatStringNumTimesWithWhile('abc', 3)); // use a 'do...while' loop function repeatStringNumTimesWithDoWhile(str, num) { // add your code here - return str; + /* this code is not working, i still + struggling with do...while loop */ + string = ''; + do { + string += str; + num--; + } while (num > n); + return string; } console.log('while', repeatStringNumTimesWithDoWhile('abc', 3)); diff --git a/Week3/homework/4-step3.js b/Week3/homework/4-step3.js index 52a0e9d74..3cb29dd5e 100644 --- a/Week3/homework/4-step3.js +++ b/Week3/homework/4-step3.js @@ -1,2 +1,7 @@ 'use strict'; // paste your freeCodeCamp solutions in here +function Dog () { + this.name = "Jumbo"; + this.color = "Black"; + this.numLegs = 4; + } \ No newline at end of file diff --git a/Week3/homework/5-step3.js b/Week3/homework/5-step3.js index 52a0e9d74..13ac44790 100644 --- a/Week3/homework/5-step3.js +++ b/Week3/homework/5-step3.js @@ -1,2 +1,10 @@ 'use strict'; // paste your freeCodeCamp solutions in here +function Dog() { + this.name = "Rupert"; + this.color = "brown"; + this.numLegs = 4; + } + // Add your code below this line + + let hound = new Dog(); \ No newline at end of file diff --git a/Week3/homework/step4-bonus.js b/Week3/homework/step4-bonus.js index 4e89b29e7..bd118a74d 100644 --- a/Week3/homework/step4-bonus.js +++ b/Week3/homework/step4-bonus.js @@ -3,8 +3,14 @@ const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; // Add your function here. Try and come up with a good name for this function - +function removeDoubles(foo) { + const uniqueLetters = []; + for (let i = 0; i < foo.length; i++){ + uniqueLetters.push(foo[i]); + } + return uniqueLetters; +} // Replace `yourFunction` with the name of the function you just created -const uniqueValues = yourFunction(values); +const uniqueValues = removeDoubles(values); console.log(uniqueValues);