├── .DS_Store ├── .eslintrc.json ├── .gitignore ├── .travis.yml ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── Week1 ├── LESSONPLAN.md ├── MAKEME.md ├── README.md ├── homework │ ├── app.js │ ├── index.html │ └── style.css ├── js-exercises │ ├── ex1-bookList.html │ ├── ex1-bookList.js │ ├── ex2-aboutMe.html │ ├── ex2-aboutMe.js │ ├── ex3-hijackLogo.js │ ├── ex4-whatsTheTime.html │ ├── ex4-whatsTheTime.js │ ├── ex5-catWalk.html │ └── ex5-catWalk.js └── project │ ├── index.css │ ├── index.html │ └── index.js ├── Week2 ├── LESSONPLAN.md ├── MAKEME.md ├── README.md ├── homework │ ├── maartjes-work.js │ └── map-filter.js ├── js-exercises │ ├── ex1-oddOnesOut.js │ ├── ex2-whatsYourMondayWorth.js │ ├── ex3-lemonAllergy.js │ ├── ex4-collectiveAge.js │ ├── ex5-myFavoriteHobbies.html │ └── ex5-myFavoriteHobbies.js ├── project │ ├── index.html │ └── index.js └── test │ ├── maartjes-work.test.js │ └── map-filter.test.js ├── Week3 ├── LESSONPLAN.md ├── MAKEME.md ├── README.md ├── js-exercises │ ├── ex1-AddSix.js │ ├── ex2-RemoveDuplicates.js │ ├── ex3-GuessTheOutput.js │ ├── ex4-GuessMore.js │ └── ex5-LotteryMachine.js ├── old-homework │ ├── step2-1.js │ ├── step2-2.js │ ├── step2-3.js │ ├── step2-4.js │ ├── step2-5.js │ ├── step2-6.js │ ├── step2-7.js │ ├── step3-bonus.js │ └── step3.js ├── project │ ├── index.html │ └── index.js └── test │ ├── console-test.js │ ├── step2-1.test.js │ ├── step2-2.test.js │ ├── step2-3.test.js │ ├── step2-4.test.js │ ├── step2-5.test.js │ ├── step2-6.test.js │ ├── step3-bonus.test.js │ └── step3.test.js ├── assets ├── array-methods-exercises.js ├── call_stack_example.png ├── callbacks.js ├── domtree.png ├── hoisting.js ├── javascript-sync-vs-async.png ├── javascript2.png ├── pomodoro.png ├── randomquotegenerator.png ├── scope.js ├── scopes.png ├── servicequality.png ├── simple-dom.png ├── submit-homework.png ├── sync-async.js ├── tipcalculator.png ├── weekflow.png └── wilgert.png ├── hand-in-homework-guide.md ├── package-lock.json ├── package.json ├── prettier.config.js └── test └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HackYourFuture/JavaScript2/8e77a7ea1bee5d6aed42d4bee5fcb6f683c4f40c/.DS_Store -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["airbnb", "prettier"], 3 | "plugins": ["prettier"], 4 | "env": { 5 | "browser": true, 6 | "jest": true 7 | }, 8 | "rules": { 9 | "prettier/prettier": ["error"], 10 | "strict": "off", 11 | "func-names": "off", 12 | "import/no-dynamic-require": "off", 13 | "no-console": "off", 14 | "no-param-reassign": "off", 15 | "no-plusplus": "off", 16 | "no-restricted-syntax": "off", 17 | "object-shorthand": "off", 18 | "operator-assignment": "off", 19 | "prefer-arrow-callback": "off", 20 | "prefer-destructuring": "off", 21 | "prefer-template": "off", 22 | "trailing-comma": "off", 23 | "linebreak-style": "off" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | .netlify 61 | dist/ 62 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '10' 4 | 5 | script: 6 | - npm run lint 7 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.formatOnType": true, 4 | "editor.formatOnPaste": true, 5 | "editor.detectIndentation": false, 6 | "editor.tabSize": 2, 7 | "cSpell.words": [ 8 | "Debouncing", 9 | "Maartje", 10 | "blabla", 11 | "codewars", 12 | "keyup", 13 | "maartje's", 14 | "maartjes", 15 | "roverjs", 16 | "taalmap", 17 | "trollface" 18 | ] 19 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This work is licensed under the Creative Commons Attribution 4.0 International License. 2 | To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ 3 | or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DEPRECATED - JavaScript 2 2 | This module has been replace with the Browsers module, find it [here](https://github.com/HackYourFuture/Browsers) 3 | 4 | 5 | ```If you were to ask a random person on the street the question "What is a browser?", you'll most likely get a variety of (incorrect) answers. For proof, check [this](https://www.youtube.com/watch?v=o4MwTvtyrUQ) out. 6 | 7 | You might be one of those people right now, but after this module no more. In **JavaScript2** you'll learn all about how to use JavaScript within the browser. 8 | 9 | ## Learning goals 10 | 11 | In order to successfully complete this module you will need to master the following: 12 | 13 | - Understand what the `DOM` is 14 | - Use the basics of `DOM Manipulation` 15 | - Differentiate between `synchronous` and `asynchronous` operations 16 | - Gain awareness of the inner workings of JavaScript 17 | - Learn to think based on `principles`, instead of libraries and frameworks 18 | 19 | ## How to use this repository 20 | 21 | ### Repository content 22 | 23 | This repository consists of 3 essential parts: 24 | 25 | 1. `README`: this document contains all the required theory you need to understand **while** working on the homework. It contains not only the right resources to learn about the concepts, but also lectures done by HackYourFuture teachers. This is the **first thing** you should start with every week 26 | 2. `MAKEME`: this document contains the instructions for each week's homework. Start with the exercises rather quickly, so that you can ground the concepts you read about earlier. 27 | 3. `LESSONPLAN`: this document is meant for teachers as a reference. However, as a student don't be shy to take a look at it as well! 28 | 29 | ### How to study 30 | 31 | Let's say you are just starting out with the JavaScript2 module. This is what you do... 32 | 33 | 1. The week always starts on **Wednesday**. First thing you'll do is open the `README.md` for that week. For the first week of `JavaScript2`, that would be [Week1 Reading](/Week1/README.md) 34 | 2. You spend **Wednesday** and **Thursday** going over the resources and try to get a basic understanding of the concepts. In the meanwhile, you'll also implement any feedback you got on last week's homework (from the JavaScript1 module) 35 | 3. On **Friday** you start with the homework, found in the `MAKEME.md`. For the first week of `JavaScript2`, that would be [Week1 Homework](/Week1/MAKEME.md) 36 | 4. You spend **Friday** and **Saturday** playing around with the exercises and write down any questions you might have 37 | 5. **DEADLINE 1**: You'll submit any questions you might have before **Saturday 23.59**, in the class channel 38 | 6. On **Sunday** you'll attend class. It'll be of the Q&A format, meaning that there will be no new material. Instead your questions shall be discussed and you can learn from others 39 | 7. You spend **Monday** and **Tuesday** finalizing your homework 40 | 8. **DEADLINE 2**: You submit your homework to the right channels (GitHub) before **Tuesday 23.59**. If you can't make it on time, please communicate it with your mentor 41 | 9. Start the new week by going back to point 1! 42 | 43 | In summary: 44 | 45 | ![Weekflow](assets/weekflow.png) 46 | 47 | To have a more detailed overview of the guidelines, please read [this document](https://docs.google.com/document/d/1JUaEbxMQTyljAPFsWIbbLwwvvIXZ0VCHmCCN8RaeVIc/edit?usp=sharing) or ask your mentor/class on Slack! 48 | 49 | ### Video lectures 50 | 51 | For each module HackYourFuture provides you with video lectures. These are made by experienced software developers who know what they're talking about. The main teacher for this module will be [Wilgert Velinga](https://hackyourfuture.slack.com/team/UGTGC0T41): senior frontend developer and consultant! 52 | 53 | You can find out more about him here: 54 | 55 | - [GitHub](https://github.com/wilgert) 56 | - [@Wilgert on Slack](https://hackyourfuture.slack.com/team/UGTGC0T41) 57 | 58 | Learn from Wilgert in the following playlist of videos he has made for you! (Click on the image to open the link) 59 | 60 | HYF Video 61 | 62 | ## Planning 63 | 64 | | Week | Topic | Reading Materials | Homework | Lesson Plan | 65 | | ---- | -------------------------------------------------------------------- | ------------------------------ | ------------------------------- | -------------------------------------- | 66 | | 1. | Document-Object Model (DOM), DOM manipulation | [Reading W1](/Week1/README.md) | [Homework W1](/Week1/MAKEME.md) | [Lesson Plan W1](/Week1/LESSONPLAN.md) | 67 | | 2. | Synchronous vs. asynchronous, Event Loop, Callbacks, Array Functions | [Reading W2](/Week2/README.md) | [Homework W2](/Week2/MAKEME.md) | [Lesson Plan W2](/Week1/LESSONPLAN.md) | 68 | | 3. | Scope, Hoisting, Closures, Thinking like a programmer II | [Reading W3](/Week3/README.md) | [Homework W3](/Week3/MAKEME.md) | [Lesson Plan W3](/Week1/LESSONPLAN.md) | 69 | | 4. | Test | [Details](/test/README.md) | - | - | 70 | 71 | ## Finished? 72 | 73 | Did you finish the module? Good job! You're doing great! 74 | 75 | If you feel ready for the next challenge, click [here](https://www.github.com/HackYourFuture/JavaScript3) to go to JavaScript3! 76 | 77 | _The HackYourFuture curriculum is subject to CC BY copyright. This means you can freely use our materials, but just make sure to give us credit for it :)_ 78 | 79 | Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.``` 80 | -------------------------------------------------------------------------------- /Week1/LESSONPLAN.md: -------------------------------------------------------------------------------- 1 | # Lesson Plan JavaScript2 Week 1 2 | 3 | ## Agenda 4 | 5 | The purpose of this class is to introduce to the student: 6 | 7 | - How a webpage is made up of objects (DOM) 8 | - How JavaScript can be used to manipulate those objects (DOM manipulation) 9 | - Commonly used browser defined functions and properties 10 | 11 | ## Core concepts 12 | 13 | FIRST HALF (12.00 - 13.30) 14 | 15 | > Is this your first lecture for this class? 16 | > Please introduce yourself briefly: 17 | > 18 | > - Job 19 | > - Education 20 | > - City 21 | > - Why you love programming (if you do) 22 | 23 | ## 1. Document Object Model (DOM) 24 | 25 | ### Explanation 26 | 27 | The [Document Object Model (DOM)](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction) is an _object-oriented representation_ of a web page (HTML document). Every HTML element (ex. `h1`, `p` or `img`) is corrected first and then converted into a JavaScript object by the browser, making it possible for us to use JavaScript to change the contents. Using JavaScript code we can access the `DOM` through a global object called `document` or `window.document`. 28 | 29 | ### Example 30 | 31 | > Show the student the following HTML in the browser, and then refer to it in the browser console. 32 | 33 | ```html 34 | 35 | 36 | 37 | My title 38 | 39 | 40 | 41 |

My header

42 |

This is a nice paragraph

43 | 47 | My link 48 | 49 | 50 | ``` 51 | 52 | ![Pictorial Representation of DOM](./../assets/domtree.png) 53 | 54 | Notice how the DOM is structured in a tree-like manner. It goes from top (highest) to bottom (lowest) level. It's very much like a family tree: the highest level is the great-great-great-grandparent, while the lowest level is the grand-grand-grand-child. 55 | 56 | ### Exercise 57 | 58 | 1. Create an HTML file including the structure of a basic webpage (including `!DOCTYPE`, `html`, `head` and `body`, 1 `h1` and 1 `p`) 59 | 2. Find out how to target the `head`, `body` and `h1` elements using the browser console 60 | 3. Present your solution and how you figured it out (_Teacher chooses two people_) 61 | 62 | ### Essence 63 | 64 | **The DOM is created by the browser: it reads your HTML file and transforms the elements into objects. We use JavaScript to select these elements in order to change them.** 65 | 66 | ## 2. Commonly used browser defined functions and properties 67 | 68 | ### Explanation 69 | 70 | As developers we can use code others have written. The browser contains predefined functions that we can use in order to get certain things done. For example, we can add/update/remove new HTML elements to the DOM. The browser also offers us properties, so that we can also play with the user's viewing experience. For example, we can modify the browser's width programmatically so we can offer a responsive website. 71 | 72 | ### Example 73 | 74 | ```js 75 | // 1. Print the current page 76 | window.print(); 77 | 78 | // 2. Get the URL from the address bar 79 | window.location.href; 80 | 81 | // 3. Make a XHR request to an external service 82 | window.fetch('https://dog.ceo/api/breeds/image/random'); 83 | ``` 84 | 85 | ### Exercise 86 | 87 | Find browser functions or properties to show how we can... 88 | 89 | 1. display an alert box? 90 | 2. find out what the browser's name is? 91 | 3. go back one page? 92 | 93 | ### Essence 94 | 95 | **We can use by the browser predefined functions and properties to shape the user's experience of our application.** 96 | 97 | SECOND HALF (14.00 - 16.00) 98 | 99 | ## 3. DOM manipulation 100 | 101 | ### Explanation 102 | 103 | `DOM manipulation` refers to the act of using JavaScript to select and modify elements within the DOM. We do this in order to provide users interactivity with the page: for example, if a button is clicked the background color changes, or if a menu item is hovered over it becomes bigger. 104 | 105 | ### Example 106 | 107 | ```html 108 | 109 | 110 | 111 | My title 112 | 113 | 114 | 115 |

My header

116 |

This is a nice paragraph

117 | 121 | 122 | My link 123 | 124 | 125 | ``` 126 | 127 | ```js 128 | // 1. Make body background color red 129 | const body = document.body; 130 | body.style.background = 'red'; 131 | 132 | // 2. Change paragraph content 133 | const p = document.querySelector('p'); 134 | p.innerHtml = 'This paragraph has changed!'; 135 | 136 | // 3. Create and add a new element to an existing HTML element 137 | const thirdLi = document.createElement('li'); 138 | const ul = document.querySelector('ul'); 139 | ul.appendChild(thirdLi); 140 | 141 | // 4. On button click alert the user! 142 | const button = document.querySelector('button'); 143 | button.addEventListener('click', function() { 144 | alert('You clicked the button!'); 145 | }); 146 | ``` 147 | 148 | ### Exercise 149 | 150 | Write JavaScript code that... 151 | 152 | 1. changes the `href` value to `https://www.hackyourfuture.net/` 153 | 2. changes the `button` text to `Make background colored!` 154 | 3. colors the `body` background to your favorite color, when the button is clicked 155 | 156 | Present your solution and how you figured it out (_Teacher chooses two people_) 157 | 158 | ### Essence 159 | 160 | **Using JavaScript we can select and modify DOM elements. In this way we can provide the user useful interactions with the webpages they're engaged in.** 161 | -------------------------------------------------------------------------------- /Week1/MAKEME.md: -------------------------------------------------------------------------------- 1 | # Homework JavaScript2 Week 1 2 | 3 | ## **Todo list** 4 | 5 | 1. Practice the concepts 6 | 2. JavaScript exercises 7 | 3. Code along 8 | 4. PROJECT: Random Quote Generator 9 | 10 | ## **1. Practice the concepts** 11 | 12 | Before we head into the exercises, it might be nice to do some interactive exercises first! In the following resource you'll find some exercises that'll teach you the basics of the interaction between JavaScript and the DOM: 13 | 14 | - [Making webpages interactive](https://www.khanacademy.org/computing/computer-programming/html-css-js) 15 | 16 | ## **2. JavaScript exercises** 17 | 18 | > Inside of your `JavaScript2` fork, find the folder called `Week1`. Inside of that folder, find the folder called `js-exercises`. In this folder you will find five `.js` files (sometimes with a matching `.html` file), one for each exercise where you need to write your code. Please use the correct file for the respective exercise. 19 | 20 | **Exercise 1: The book list** 21 | 22 | I'd like to display my three favorite books inside a nice webpage! 23 | 24 | ```js 25 | const books = [ 26 | { 27 | title: 'The Design of Everyday Things', 28 | author: 'Don Norman', 29 | alreadyRead: false 30 | }, 31 | { 32 | title: 'The Most Human Human', 33 | author: 'Brian Christian', 34 | alreadyRead: true 35 | }, 36 | { 37 | title: 'The Pragmatic Programmer', 38 | author: 'Andrew Hunt', 39 | alreadyRead: true 40 | } 41 | ]; 42 | ``` 43 | 44 | 1. Iterate through the array of books. 45 | 2. For each book, create a `

` element with the book title and author and append it to the page. 46 | 3. Use a `