forked from HackYourFuture/JavaScript2
-
Notifications
You must be signed in to change notification settings - Fork 33
Ivy js2 wk2 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chichiglacierz
wants to merge
5
commits into
foocoding:master
Choose a base branch
from
chichiglacierz:Ivy-Js2-wk2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ivy js2 wk2 #20
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,160 @@ | ||
'use strict'; | ||
|
||
{ | ||
const bookTitles = [ | ||
// Replace with your own book titles | ||
'harry_potter_chamber_secrets', | ||
]; | ||
|
||
// Replace with your own code | ||
console.log(bookTitles); | ||
'use strict'; | ||
|
||
// array of books containing 10 strings. lowercase | ||
const bookTitles = [ | ||
'going_down_river_road', | ||
'the_river_and_the_source', | ||
"salem's_lot", | ||
'americanah', | ||
'things_fall_apart', | ||
'animal_farm', | ||
'the_river_between', | ||
'the_dead_stay_dumb', | ||
'arrow_of_god', | ||
'a_song_of_ice_and_fire', | ||
]; | ||
|
||
// Replace with your own code | ||
// const showBooks = Object.values(bookNames); | ||
// console.log(bookTitles); | ||
|
||
// the part below not showing on console on chrome | ||
// function printBookNames(bookTitles) { | ||
// console.table(bookTitles); | ||
// } | ||
//printing out the string of the above array produces: | ||
// for (let i = 0; i < bookNames.length; i++) { | ||
// console.log(bookNames[i]); | ||
// } | ||
// eslint-disable-next-line no-unused-vars | ||
// 1.3. Make a function (or functions) that generate a ul with li elements for each book ID in the array using a for loop. | ||
|
||
// 1.4 create object containing details of each book: | ||
const bookInfo = { | ||
going_down_river_road: { | ||
title: 'Going Down River Road', | ||
author: 'Meja Mwangi', | ||
language: 'English', | ||
published: 1976, | ||
}, | ||
|
||
the_river_and_the_source: { | ||
title: 'The River And The Source', | ||
author: 'Margaret Ogola', | ||
language: 'English', | ||
published: 1994, | ||
}, | ||
|
||
homing_in: { | ||
title: 'Salem´s Lot', | ||
author: 'Stephen King', | ||
language: 'English', | ||
published: 1975, | ||
}, | ||
|
||
americanah: { | ||
title: 'Americanah', | ||
author: 'Chimamanda Ngozi Adichie', | ||
language: 'English', | ||
published: 2013, | ||
}, | ||
|
||
things_fall_apart: { | ||
title: 'Things Fall Apart', | ||
author: 'Chinua Achebe', | ||
language: 'English', | ||
published: 1958, | ||
}, | ||
|
||
animal_farm: { | ||
title: 'Animal Farm', | ||
author: 'George Orwell', | ||
language: 'English', | ||
published: 1945, | ||
}, | ||
|
||
the_river_between: { | ||
title: 'The River Between', | ||
author: 'Ngugi wa Thiong´o', | ||
language: 'English', | ||
published: 1965, | ||
}, | ||
|
||
the_dead_stay_dumb: { | ||
title: 'The Dead Stay Dumb', | ||
author: 'James Hardley Chase', | ||
language: 'English', | ||
published: 1939, | ||
}, | ||
|
||
arrow_of_god: { | ||
title: 'Arrow of God', | ||
author: 'Chinua Achebe', | ||
language: 'English', | ||
published: 1964, | ||
}, | ||
|
||
a_song_of_ice_and_fire: { | ||
title: 'A Song of Ice and Fire', | ||
author: 'George R.R. Martin', | ||
language: 'English', | ||
published: 1996, | ||
}, | ||
}; | ||
//console.log(Object.keys(bookInfo)); | ||
|
||
const bookImgs = { | ||
going_down_river_road: './bookImgs/going-down-river-road.jpg', | ||
the_river_between: './bookImgs/the_river_between.jpg', | ||
homing_in: './bookImgs/homing_in.jpg', | ||
americanah: './bookImgs/americanah.jpg', | ||
things_fall_apart: './bookImgs/things_fall_apart.jpg', | ||
animal_farm: './bookImgs/animal_farm.jpeg', | ||
arrow_of_god: './bookImgs/arrow_of_god.jpg', | ||
a_song_of_ice_and_fire: './bookImgs/a_song_of_ice_and_fire.jpg', | ||
the_dead_stay_dumb: './bookImgs/the_dead.jpg', | ||
the_river_and_the_source: './bookImgs/the_river.jpg', | ||
}; | ||
|
||
function bookList() { | ||
const bookUl = document.createElement('ul'); | ||
bookUl.id = 'bookContainer'; | ||
document.body.appendChild(bookUl); | ||
|
||
for (let key in bookInfo) { | ||
const bookItems = document.createElement('li'); | ||
bookItems.id = 'book-items'; | ||
const bookTitle = document.createElement('h2'); | ||
bookTitle.id = 'book-title'; | ||
bookTitle.innerText = bookInfo[key].title; | ||
bookItems.appendChild(bookTitle); | ||
|
||
const bookDiv = document.createElement('div'); | ||
bookDiv.setAttribute('id', key); | ||
bookItems.appendChild(bookDiv); | ||
|
||
const content = document.createAttribute('div'); | ||
content.id = 'book-contents'; | ||
content.innerText = `<p>Title: ${bookInfo[key].title}</p> | ||
<p>Author: ${bookInfo[key].author}</p> | ||
<p>Language: ${bookInfo[key].language}</p> | ||
<p>Published: ${bookInfo[key].published}</p>`; | ||
//bookDiv.appendChild(content); | ||
bookUl.appendChild(bookItems); | ||
} | ||
//creating a function to add images to books: | ||
for (const bookKey in bookImgs) { | ||
const bookDiv = document.getElementById(bookKey); | ||
const imgContainer = document.createElement('div'); | ||
imgContainer.id = 'book-img'; | ||
bookDiv.appendChild(imgContainer); | ||
|
||
//adding pic from book obj with attr | ||
const pic = document.createElement('img'); | ||
pic.setAttribute('src', bookImgs[bookKey]); | ||
imgContainer.appendChild(pic); | ||
} | ||
} | ||
bookList(); |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
<!-- replace this with your HTML content --> | ||
<!-- replace this with your HTML content --> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>Week-1 Js 2</title> | ||
<link rel="styleSheet" type="text/css" href="./style.css" /> | ||
</head> | ||
|
||
<body> | ||
<script type="text/javascript" src="./app.js"></script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
/* add your styling here */ | ||
/* add your styling here */ | ||
body { | ||
font-family: 'Helvetica Neue', Helvetica, sans-serif; | ||
} |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
'use strict'; | ||
|
||
function doubleOddNumbers(numbers) { | ||
// Replace this comment and the next line with your code | ||
// the following iterates the variables in numbers(with filter) and checking if they´re divisible by 2 | ||
// const newNumbers = []; | ||
// for (let i = 0; i =numbers.length) | ||
numbers = numbers.filter(num => num % 2 === 1).map(num => num * 2); | ||
console.log(numbers); | ||
return numbers; | ||
} | ||
|
||
const myNumbers = [1, 2, 3, 4]; | ||
console.log(doubleOddNumbers(myNumbers)); | ||
console.log(doubleOddNumbers(myNumbers)); // output : [2, 6] | ||
|
||
// Do not change or remove anything below this line | ||
module.exports = { | ||
myNumbers, | ||
doubleOddNumbers, | ||
}; | ||
//completed |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "homework", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "step2-1.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and clear code 👍