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

Skip to content

Homework week1 #2

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
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 0 additions & 25 deletions .eslintrc.json

This file was deleted.

62 changes: 1 addition & 61 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,61 +1 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

.netlify
dist/
node_modules
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions LICENSE

This file was deleted.

8 changes: 4 additions & 4 deletions Week1/MAKEME.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Modify the (mostly empty) files in the `Week1/homework` folder for this step.

**1.2** Open the empty `index.html` and add the required HTML to load the `app.js` file. Open `index.html` in the browser and confirm that the `console.log` statement shows the array. (Open the Chrome Developer Tools and inspect the console.)

**1.3** Remove the temporary `console.log` from step 1.1. Make a function (or functions) that generate a `ul` with `li` elements for each book ID in the array using a `for` loop. Make sure that the function names you choose are an accurate reflection of what they do. As a reminder, here are the recommended [Naming Conventions](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/naming_conventions.md).
**1.3** Remove the temporary `console.log` from step 1.1. Make a function (or functions) that generate a `ul` with `li` elements for each book title in the array using a `for` loop. Make sure that the function names you choose are an accurate reflection of what they do. As a reminder, here are the recommended [Naming Conventions](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/naming_conventions.md).

**1.4** Make an object (_not an array!_) containing information for each book. Each property of this object should be another (i.e., nested) object with the book ID you thought up in step 1.1 as a key, and at least the following properties: `title`, `language` and `author`.
**1.4** Make an object (_not an array!_) containing information for each book. Each property of this object should be another (i.e., nested) object with the book title you thought up in step 1.1 as a key, and at least the following properties: `title`, `language` and `author`.

**1.5** Now change the function from step 1.3 that you used to display the book ID's in a list to take the actual information about the book from the object and display that. Make sure you choose the correct HTML elements for each piece of info, for instance, a heading for the title.
**1.5** Now change the function from step 1.3 that you used to display the book title in a list to take the actual information about the book from the object and display that. Make sure you choose the correct HTML elements for each piece of info, for instance, a heading for the title.

**1.6** Beautify your html page with css (use the `style.css` file for that), add sources and alts to each of the images.

**1.7** Find and download book covers for each book and construct a new object which has as keys the book IDs again, and as value the path to the image source (e.g. `{ harry_potter_blabla: './img/harry_potter_blabla.jpg', ... }`).
**1.7** Find and download book covers for each book and construct a new object which has as keys the book titles again, and as value the path to the image source (e.g. `{ harry_potter_blabla: './img/harry_potter_blabla.jpg', ... }`).

**1.8** Loop over these entries (_hint: `Object.keys(objectName)` gives you an array containing the keys_). Then write a function which places an image at the corresponding `li` element. Remember that objects are not ordered, so you cannot guarantee that the first key is the first `li` element. (_Hint: you could give each `li` item an `id` tag by modifying the function you made before._)

Expand Down
25 changes: 25 additions & 0 deletions Week1/New Text Document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const update = () => {
let value = parseInt(number.innerText);
value++;
number.innerText = value;
};

const root = document.getElementById('root');

const number = document.createElement('div');
number.style.width = '100%';
number.innerText = 0;
number.style.textAlign = 'center';
number.style.fontSize = '250%';
root.appendChild(number);

const incr = document.createElement('button');
incr.onclick = update;
incr.setAttribute('class', 'my-button');
incr.style.width = '100%';
incr.innerText = 'incr';
incr.style.textAlign = 'center';
incr.style.fontSize = '250%';
root.appendChild(incr);
6 changes: 5 additions & 1 deletion Week1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ In week one we will discuss the following topics:

Then, click on the `{ }` button in the top-right corner of the settings screen to access the settings in JSON format.


```json
/// Place your settings in this file to overwrite the default settings
{
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.minimap.enabled": false,
"editor.renderIndentGuides": true,
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"eslint.autoFixOnSave": true,
"files.autoSave": "onFocusChange",
"prettier.printWidth": 100,
"prettier.singleQuote": true,
Expand Down
14 changes: 14 additions & 0 deletions Week1/homework/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
3 changes: 3 additions & 0 deletions Week1/homework/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
142 changes: 142 additions & 0 deletions Week1/homework/MY-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
'use strict';

{
const favoriteBooks = [
//1.1 Replace with your own book titles
'harry_potter_chamber_secrets',
'call_of_the_wild',
'the_turtle',
'snowball_and_the_bunny_adventures',
'chicken_little',
'hey_friend',
'it_is_chilly_out_there',
'stone_and_pain',
'maybe_tomorrow',
'alise_in_wonderland',
];

// 1.2 Replace with your own code

//console.log(favoriteBooks);

//1.3 Remove the temporary console.log from step 1.1. Make a function (or functions) that generate a ul with li elements for each book ID
// in the array using a for loop. Make sure that the function names you choose are an accurate reflection of what they do. As a reminder,
//here are the recommended Naming Conventions.

// let booksList = document.createElement('ul');
// booksList.setAttribute('id', 'li');
// document.body.appendChild(booksList);

// let index;
// for (index in favoriteBooks) {
// let booksListItem = document.createElement('li');
// booksList.appendChild(booksListItem);
// booksListItem.textContent = favoriteBooks[index];
// }
// }
// generateList();
// function generateList(){


// // 1.4 Make an object (not an array!) containing information for each book. Each property of this object should be another (i.e., nested)
// object with the book ID you thought up in step 1.1 as a key, and at least the following properties: title, language and author.
let bookProperties = {
harry_potter_chamber_secrets:{
title:"Harry Potter: Chamber of Secrets",
language:"English",
author:"Joanne K. Rowling",
},
call_of_the_wild:{
title:"Call of the Wild",
language:"English",
author:"Jack London",
},
the_turtle:{
title:"The Turtle",
language:"Anna -ish",
author:"Imaginery",
},
snowball_and_the_bunny_adventures:{
title:"Snowball and the Bunny Adventures",
language:"Anna -ish",
author:"Imaginery van Children",
},
chicken_little:{
title:"Chicken Little - The Sky is Falling",
language:"English",
author:"Folk Tale",
},
hey_friend:{
title:"Hey Friend",
language:"Anna -ish",
author:"Imaginery",
},
it_is_chilly_out_there:{
title:"It is Chilly out There",
language:"Anna -ish",
author:"Imaginery",
},
stone_and_pain:{
title:"Stone and Pain - The Life of Michelangelo Buonarotti",
language:"Chech",
author:"Karrel Schulz",
},
maybe_tomorrow:{
title:"Maybe Tomorrow",
language:"Anna -ish",
author:"Imaginery Delayer",
},
alise_in_wonderland:{
title:"Alise in Wonderland",
language:"English",
author:"Lewis Carrol",
}
}


// // 1.5 Now change the function from step 1.3 that you used to display the book ID's in a list to take the actual information about the book
// from the object and display that. Make sure you choose the correct HTML elements for each piece of info, for instance, a heading for the title.
function generateList(){
let booksList = document.createElement('ul');
booksList.setAttribute('id', 'li');
document.body.appendChild(booksList);

let index;

for (index in favoriteBooks) {
let booksListItem = document.createElement('li');
booksList.appendChild(booksListItem);

let BooksID = favoriteBooks[index];
booksListItem.textContent = favoriteBooks[index];
}
}
generateList();
//Gabe's example
// const unorderedListElement = document.createElement('ul');

// for (let bookTitleKey in bookTitles) {
// const bookUL = document.createElement ('ul');

// const authorListEl = document.createElement('li')
// authorListEl.innerText = bookTitles[bookTitleKey].author;
// bookUL.appendChild(authorListEl)

// const titleListEl = document.createElement('li')
// titleListEl.innerText = bookTitles[bookTitleKey].author;
// bookUL.appendChild(titleListEl)

// const yearListEl = document.createElement('li')
// yearListEl.innerText = bookTitles[bookTitleKey].author;
// bookUL.appendChild(yearListEl)
// }

// // 1.6 Beautify your html page with css (use the style.css file for that), add sources and alts to each of the images.

// // 1.7 Find and download book covers for each book and construct a new object which has as keys the book IDs again, and as value the path to
// the image source (e.g. { harry_potter_blabla: './img/harry_potter_blabla.jpg', ... }).

// // 1.8 Loop over these entries (hint: Object.keys(objectName) gives you an array containing the keys). Then write a function which places an
// image at the corresponding li element. Remember that objects are not ordered, so you cannot guarantee that the first key is the first li element.
// (Hint: you could give each li item an id tag by modifying the function you made before.)
}
30 changes: 30 additions & 0 deletions Week1/homework/adding_numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const assert = chai.assert.deepStrictEqual
const range = _.range
const print = console.log
print('##### begin #####')
assert(range(5), [0,1,2,3,4])

/*function sumAll(a, b) {
const max = Math.max(a, b);
const min = Math.min(a, b);
let result = 0;
for (var i=min; i <= max; i++){
result += i;
}
return result;
}*/

function sumAll(a, b) {
const avg = (a+b)/2
const n = Math.abs(b-a)+1
return avg*n;
}

assert(10, sumAll(1, 4));
assert(10, sumAll(4, 1));
assert(1, sumAll(1, 1));
assert(45, sumAll(5, 10));
assert(5050, sumAll(1, 100));


print('##### end #####')
11 changes: 0 additions & 11 deletions Week1/homework/app.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index.js":"function Dog(name, color) {\nthis.name = name;\nthis.color = color;\nthis.numLegs = 4; \n}\n\nlet terrier = new Dog(\"Gafgaf\", \"brown\");"}
13 changes: 13 additions & 0 deletions Week1/homework/index.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Foo Coding</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
<script src="adding_numbers.js"></script>
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
</head>
<body>
</body>
</html>
Loading