From e0d4b3d58e0a135944be573fc19f62723eed4ea8 Mon Sep 17 00:00:00 2001 From: behuFTP Date: Thu, 20 Dec 2018 09:46:05 +0100 Subject: [PATCH 001/280] Restructure js3 --- JavaScript2/Week4/homework.md | 69 +++--- JavaScript2/Week4/preparation.md | 7 +- JavaScript2/Week4/readme.md | 18 +- JavaScript2/Week4/review.md | 237 ++++---------------- JavaScript2/Week5/homework.md | 105 ++++----- JavaScript2/Week5/preparation.md | 26 +-- JavaScript2/Week5/reading.md | 30 --- JavaScript2/Week5/readme.md | 17 +- JavaScript2/Week5/review.md | 176 +++++---------- JavaScript2/Week6/homework.md | 143 ++++++------ JavaScript2/Week6/homework/hyfBayHelpers.js | 68 ++++++ JavaScript2/Week6/homework/index.html | 58 +++++ JavaScript2/Week6/homework/main.css | 93 ++++++++ JavaScript2/Week6/homework/main.js | 54 +++++ JavaScript2/Week6/homework/movies.js | 1 + JavaScript2/Week6/preparation.md | 8 + JavaScript2/Week6/reading.md | 25 --- JavaScript2/Week6/readme.md | 17 ++ JavaScript2/Week6/review.md | 188 +++++----------- JavaScript2/readme.md | 6 +- 20 files changed, 644 insertions(+), 702 deletions(-) delete mode 100644 JavaScript2/Week5/reading.md create mode 100644 JavaScript2/Week6/homework/hyfBayHelpers.js create mode 100644 JavaScript2/Week6/homework/index.html create mode 100644 JavaScript2/Week6/homework/main.css create mode 100644 JavaScript2/Week6/homework/main.js create mode 100644 JavaScript2/Week6/homework/movies.js create mode 100644 JavaScript2/Week6/preparation.md delete mode 100644 JavaScript2/Week6/reading.md create mode 100644 JavaScript2/Week6/readme.md diff --git a/JavaScript2/Week4/homework.md b/JavaScript2/Week4/homework.md index 30348c7d..464bea0f 100644 --- a/JavaScript2/Week4/homework.md +++ b/JavaScript2/Week4/homework.md @@ -1,49 +1,53 @@ # Homework -First off, congratulations on coming this far, well done! +## So why this homework? +Interacting with the DOM is a crucial part of building a website. If we cannot interact with the DOM annd the javascript we write cannot be used in a browser. Connecting javascript to the browser opens up a new world of possibilities where only the imagination is the limiting factor. -## Step 1: Lets get real comfortable with map, filter and sort. +![books](https://media.giphy.com/media/PkQeAkvhRrWoM/giphy.gif) +## Book site +1. Open a new js file and start by declaring an array that contains 10 strings. These strings should be of book titles you have read (or made up) and be lowercase without spaces or special characters so that you can use these later as Id's. (Example: Harry Potter's - The Chamber of Secrets -> `harry_potter_chamber_secrets`). -Use the carGenerator function to generate 10 cars. The file with the function is here: -[carGenerator.js](/JavaScript2/Week4/assets/carGenerator.js) +2. Create a basic html file called index.html and use it to load the js file, confirm the console.log show the array. (This is for debugging and making sure everything is in order. Delete it later when you're done :)) -You call it like this: -generateCars(10); +3. Make a function (or functions) that generate a `ul` with `li` elements for each book ID in the array using a for loop. -Create the following arrays: +4. Make an object containing information for each book. Each item (object) in this object should have the book ID you thought up in point 1 as a key, and it should have at least the following fields: title, language and author. -- 1.1: Cars with speeds between 30 and 60 +5. Now change the function 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 right html elements for each piece of info, for instance, a heading for the title. -- 1.2: The makes of the cars that are not lightyellow, so the array is going to look like this: ['BMW', 'Fiat'] etc +6. Beautify your html page with css, add sources and alts to each of the images. + +7. Download book covers for each book, construct a new Object which has as keys the bookId's again, and as value the path to the image source (e.g. `{"harry_potter_blabla": "./img/harry_potter_blabla.jpg", ...}`). Now 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_) -- 1.3: Lets change the cars array so it can be read by a danish person. Return an array of objects where the key in the object called speed is called fart (danish for speed), the make is called maerke and the color is called farve. The output will look kind of like this: +![Spirit animal](https://media.giphy.com/media/26xBBMyZgK6xFJDoc/giphy.gif) -```js -[ - { - maerke: 'Volvo', - fart: 45, - farve: 'lightYellow', - } -]; -``` +## Spirit animal name generator +Lets create a page where a users writes his name in an input element. The user then clicks a button. The user will now receive a spirit animal name, fx Benjamin - The fullmoon wolf. +### Markup time! +Create an input element, a button and a tag to display the spirit animal into. -## Step 2: Some Challenges -Let's practice working with Objects and Arrays. Go to FreeCodeCamp and complete all challenges under "Object Oriented and Functional Programming" and the _first four challenges_ under "Basic Algorithm Scripting", up until 'Find the longest word in a string.' -https://www.freecodecamp.org/challenges/store-multiple-values-in-one-variable-using-javascript-arrays +### Setting up the events +When the user clicks the button, get the name the user wrote in the input field. -## Step 3: Custom challenge -1. Go to https://api.github.com/orgs/HackYourFuture-CPH/repos, you will see a list of the repositories our HYF organization has (yes it's a lot of JSON). -2. You can copy the JSON and put it in a string at the top of your `.js` file use this tool for that: https://jsonformatter.org/. Copy the json text into the jsonformatter and press this key: -> ![Variables are like boxes](./assets/jsonformatter.PNG) -Now you have a json string you can copy into your file. Now print the name of the 3rd github repository to the console. -3. Make a `