Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

My homework Week3 #199

Closed
wants to merge 3 commits into from
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
98 changes: 96 additions & 2 deletions Week1/homework/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
15 changes: 15 additions & 0 deletions Week2/homework/maartjes_work.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
7 changes: 7 additions & 0 deletions Week2/homework/map_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 1 addition & 0 deletions Week3/homework/1-step3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

function foo(func) {
// What to do here?
return func
}
Copy link

Choose a reason for hiding this comment

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

Not quite. All you will do here is return the function object. You want to call func and return the value from calling func.

....
return func();
....


function bar() {
Expand Down
21 changes: 18 additions & 3 deletions Week3/homework/3-step3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,38 @@
// use a 'for' loop
Copy link

Choose a reason for hiding this comment

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

Where did 2-step3.js go to?

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));

// use a 'while' loop
function repeatStringNumTimesWithWhile(str, num) {
// add your code here
return str;
while (num > 0) {
Copy link

Choose a reason for hiding this comment

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

You have to define string before you can use it.
This is where your program errors out because it cannot find string.
It is very obvious that you have not run or tested your program, otherwise you would have seen the error message, and been able to correct the problem which is:

let string = '';

string += str;
num--;
}
return string;
}

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));
5 changes: 5 additions & 0 deletions Week3/homework/4-step3.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
'use strict';
// paste your freeCodeCamp solutions in here
function Dog () {
this.name = "Jumbo";
this.color = "Black";
this.numLegs = 4;
}
Copy link

Choose a reason for hiding this comment

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

Correct. ✅
Just wondering why you removed the line that actually creates an instance of a Dog.

8 changes: 8 additions & 0 deletions Week3/homework/5-step3.js
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

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

This question was about nested loops, no the Dog.


let hound = new Dog();
10 changes: 8 additions & 2 deletions Week3/homework/step4-bonus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];
Copy link

Choose a reason for hiding this comment

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

I seem to be missing, 6-step3.js, 7-step3.js, and step4.js.


// 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]);
Copy link

Choose a reason for hiding this comment

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

All you are doing here is copying the whole array. Not removing the duplicate values.
You need to check first whether the value already exists in uniqueLetters and if it does just skip to the next iteration of the loop, and if it does not, add it to uniqueLetters.

}
return uniqueLetters;
}
// Replace `yourFunction` with the name of the function you just created
const uniqueValues = yourFunction(values);
const uniqueValues = removeDoubles(values);

console.log(uniqueValues);
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.