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.

keyya Homework Week 2 #184

Closed
wants to merge 4 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
135 changes: 127 additions & 8 deletions Week1/homework/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,130 @@
'use strict';
{
const bookTitles = [
// Replace with your own book titles
'harry_potter_chamber_secrets'
];
let theBooksIRead = [
"harry_potter_and_the_deathly_hallows",
"The_Baloch_and_Balochistan",
"The_Baloch_Conflict_with_Iran_and_Pakistan",
"Balochistan:_At_a_Crossroads_Reviews",
"The_Alchemist",
"The_Night_Bird",
" From_Sand_and_Ash",
"Dead_Certain",
" I_Am_Watching_You ",
"You_The_Letter_by_Kathryn_Hughes"
];

//console.log(theBooksIRead);

// Replace with your own code
console.log(bookTitles);
function generateItems() {
let ul = document.createElement("ul");

theBooksIRead.forEach(function (book) {
console.log(book);

let li = document.createElement("li");
ul.appendChild(li);
li.innerHTML += book;
});
document.body.appendChild(ul);
}
//generateItems();

let myBooksInformation = {
harry_potter_and_the_deathly_hallows: {
title: "Harry Potter and the Deathly Hallows",
language: "English",
author: "J. K. Rowling"
},
les_miserables: {
title: "The Baloch and Balochistan",
language: "English",
author: "Naseer Dashti"
},
da_vinci_code: {
title: " The Baloch Conflict with Iran and Pakistan",
language: "English",
author: "Naseer Dashti"
},
to_kill_a_mockingbird: {
title: "Balochistan: At a Crossroads Reviews",
language: "English",
author: "Willem Marx"
},
hero_of_our_time: {
title: "The Alchemist ",
language: "English",
author: "PAULO COELHO"
},
don_quixote: {
title: "The Night Bird",
language: "English",
author: "Brian Freeman"
},
returning_to_haifa: {
title: "From Sand and Ash",
language: "English",
author: "Amy Harmon"
},
beirut_nightmares: {
title: "Dead Certain",
language: "Englsih",
author: "Adam Mitzner"
},
doctor_zhivago: {
title: " I Am Watching You",
language: "English",
author: "Teresa Driscoll"
},
song_of_ice_and_fire: {
title: "The Letter' by Kathryn Hughes",
language: "English",
author: " Kathryn Hughes"
}
};

function generateBooksList() {
let myBooksInfo = document.createElement("ul");
document.body.appendChild(myBooksInfo);

for (let booksId in myBooksInformation) {
let li = document.createElement("li");
li.setAttribute("id", booksId);
myBooksInfo.appendChild(li);

let b_title = document.createElement("h2");
li.appendChild(b_title);
b_title.innerHTML = myBooksInformation[booksId].title;

let b_language = document.createElement("p");
li.appendChild(b_language);
b_language.innerHTML = myBooksInformation[booksId].language;

let b_author = document.createElement("h4");
li.appendChild(b_author);
b_author.innerHTML = "by : < " + myBooksInformation[booksId].author + " >";
};
}

generateBooksList();

let MyBookCovers = {
harry_potter_and_the_deathly_hallows: "https://media.bloomsbury.com/rep/bj/9780747591061.jpg",
The_Baloch_and_Balochistan: "https://images-na.ssl-images-amazon.com/images/I/51O3nqWcmqL._SX322_BO1,204,203,200_.jpg",
The_Baloch_Conflict_with_Iran_and_Pakistan: "https://thewire.in/wp-content/uploads/2017/12/Baloch-conflict.png",
Balochistan_At_a_Crossroads_Reviews: "https://images-na.ssl-images-amazon.com/images/I/81n%2B%2B6UluJL.jpg",
The_Alchemist: "https://n1.sdlcdn.com/imgs/b/y/q/624303691271_1-ed95c.jpg",
The_Night_Bird: "https://images-na.ssl-images-amazon.com/images/I/51HrCVynYBL.jpg",
From_Sand_and_Ash: "https://images-na.ssl-images-amazon.com/images/I/51KRuC%2BmItL.jpg",
Dead_Certain: "https://images-na.ssl-images-amazon.com/images/I/5132qfIGVwL._SY346_.jpg",
I_Am_Watching_You: "https://images-na.ssl-images-amazon.com/images/I/51PeVt0WznL._SY346_.jpg",
You_The_Letter_by_Kathryn_Hughes: "https://images-na.ssl-images-amazon.com/images/I/51VE8UMU35L.jpg"
};

function bookCovers() {
for (let j in myBooksInformation) {
var img = document.createElement("img");
img.setAttribute("src", MyBookCovers[j]);
img.setAttribute("alt", j);
let bookImg = document.getElementById(j);
bookImg.appendChild(img);
}
}
bookCovers();
20 changes: 19 additions & 1 deletion Week1/homework/index.html
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
<!-- replace this with your HTML content -->
DOCTYPE html>

<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Favorite Books</title>
<link href="https://fonts.googleapis.com/css?family=Gloria+Hallelujah" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div class="title">
<h1>My Favorite Books </h1>
</div>
<script src="script.js"></script>
</body>

</html>
28 changes: 28 additions & 0 deletions Week2/homework/maartjes_work.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,31 @@ const tuesday = [
const tasks = monday.concat(tuesday);

// Add your code here
{ name: 'Write a summary HTML/CSS',
duration: 180 },
{ name: 'Some web development',
duration: 120 },
{ name: 'Fix homework for class10',
duration: 20 },
{ name: 'Talk to a lot of people',
duration: 200 }
];
const tuesday = [
{ name: 'Keep writing summary',
duration: 240 },
{ name: 'Some more web development',
duration: 180 },
{ name: 'Staring out the window',
duration: 10 },
{ name: 'Talk to a lot of people',
duration: 200 },
{ name: 'Look at application assignments new students',
duration: 40 }
];
const tasks = monday.concat(tuesday);
let twoDaysIncome = tasks
.map(task => task.duration / 60)
.filter(task => task >= 2)
.map(total => total * 60)
.reduce((a, b) => a + b, 0);
console.log("Maartje earned " +twoDaysIncome+ ".00 Euro on Monday and Tuesday!");
62 changes: 61 additions & 1 deletion Week2/homework/map_filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
'use strict';

// Example implementation of map, filter, forEach
// See also: https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/map_filter.md

const numbers = [1, 2, 3, 4];

// Add your code here
function map(arr, mapFn) {
const result = [];
for (let i = 0; i < arr.length; i++) {
const elem = arr[i];
const mappedValue = mapFn(elem, i, arr);
result.push(mappedValue);
}
return result;
}

console.log('\n.map()');
console.log(map(numbers, x => x * x));
console.log(numbers.map(x => x * x));

function filter(arr, predicateFn) {
const result = [];
for (let i = 0; i < arr.length; i++) {
const elem = arr[i];
if (predicateFn(elem, i, arr)) {
result.push(arr[i]);
}
}
return result;
}

console.log('\n.filter()');
console.log(filter(numbers, x => x % 2 === 0));
console.log(numbers.filter(x => x % 2 === 0));

function reduce(arr, reducerFn, initialValue) {
let accumulator = initialValue;
for (let i = 0; i < arr.length; i++) {
const elem = arr[i];
accumulator = reducerFn(accumulator, elem, i, arr);
}
return accumulator;
}

console.log('\n.reduce()');
console.log(reduce(numbers, (acc, number) => acc + number, 0));
console.log(numbers.reduce((acc, number) => acc + number, 0));

function forEach(arr, func) {
for (let i = 0; i < arr.length; i++) {
const elem = arr[i];
func(elem, i, arr);
}
}

console.log('\n.forEach()');

let sum = 0;
forEach(numbers, x => sum += x);
console.log(sum);

sum = 0;
numbers.forEach(x => sum += x);
console.log(sum);