diff --git a/.vscode/settings.json b/.vscode/settings.json
index e14914b2e..183110862 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -12,5 +12,6 @@
"remarcmij",
"tabindex",
"whiteframe"
- ]
+ ],
+ "deno.enable": false
}
diff --git a/README.md b/README.md
index 34103e174..55310b364 100644
--- a/README.md
+++ b/README.md
@@ -1,80 +1,123 @@
-> Please help us improve and share your feedback! If you find better tutorials
-> or links, please share them by [opening a pull request](https://github.com/HackYourFuture/JavaScript3/pulls).
+# DEPRECATED - JavaScript 3
+This module has been replace with the Using API's module, find it [here](https://github.com/HackYourFuture/UsingAPIs)
-# Module #4 - JavaScript 3: Object-Oriented Programming and working with APIs (Frontend)
+```Welcome to JavaScript3! Congratulations on making it this far. You're well on your way to the top!
-
+A big part of being a programmer means moving data from one place to another. It also means working with other people's software. In this module you'll be learning about one of the core things of what makes a web developer: working with APIs!
-Welcome to JavaScript3! Congratulations on making it this far. You're well on your way to the top!
+On top of that you'll also learn how to think differently about _how_ you write your programs. Like in any field, once you've mastered a particular way of doing things you start thinking about how it could be done in a smarter, different way. In programming we call these `paradigms` and in this module you'll learn one such paradigm: Object-Oriented Programming!
-A big part of being a programmer means moving data from one place to another. It also means working with other people's software. In this module you'll be learning about one of the core things of what makes a web developer: working with APIs!
+## Before you start
+
+In the following weeks we will be using a "style guide" to help you write _"clean code"_. Because code is not only meant to be run by computers, but also to be read by humans (your colleagues, and the future version of you), it's best to make your code good. If your code is readable and nicely formatted, you're doing your colleages (and future you) a great service. The idea of a "style guide" comes from visual design, where companies often have a "visual style". For example, watch the following video to get an idea of this:
+
+### Setup Style Guide
+
+Similar to how designers have style guides for their design work, programmers often have "programming style guides". This is set of rules to follow when writing/formatting your code. The styleguide we'll be using is the one from Airbnb:
+
+- [Front-end Style Guides](https://fronteers.nl/congres/2015/sessions/front-end-style-guides-anna-debenham)
+
+The style guide we'll be using is the one from Airbnb:
+
+- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
+
+While you do not need to read this guide in detail, it is recommended that you look at sections 1-8, 12-13, 15-21 and 23.
+
+We also have tools that can automatically check whether your code is correctly formatted according to a style guide. These tools are called "linters". We will be using the JavaScript linter called "ESLint". The following packages are already added to this repository's `package.json`:
+
+The required packages you need to install before you write code according to the style guide are the following:
+
+`json
+"eslint"
+"eslint-config-airbnb-base"
+"eslint-config-prettier"
+"eslint-plugin-import"
+"eslint-plugin-prettier"
+"prettier"
+`
-On top of that you'll also learn how to think differently about how you write your programs. Like in any field, once you've mastered a particular way of doing things you start thinking about how it could be done differently. In programming we call these `paradigms` and in this module you'll learn one such paradigm: Object-Oriented Programming!
+They are already in this repository's `package.json` so all you have to do now to prepare is to execute the following command at the root of this module directory:
+
+`md
+npm install
+`
+
+### Forking the right repository
+
+Before you start with the homework, make sure you've made a fork of the right repository: [HackYourHomework/JavaScript3](https://www.github.com/hackyourhomework/javascript3)). Once you've cloned it to your computer you can proceed by making GIT branches for each week. Start at the `master` branch and execute the following (note that they're 3 different commands):
+
+`bash
+foo@bar:~$ git branch week1-YOURNAME
+foo@bar:~$ git branch week2-YOURNAME
+foo@bar:~$ git branch week3-YOURNAME
+`
+
+Then execute `git checkout week1-YOURNAME` and you can get started!
+
+If you have any questions or if something is not entirely clear ¯\_(ツ)\_/¯, please ask/comment on Slack!
## Learning goals
In order to successfully complete this module you will need to master the following:
-- Learn what an API is
-- Catch up on the history of JavaScript
-- Understand how to write more readable asynchronous JavaScript
-- Connect with different public APIs
-- Build a Single Page Application (SPA)
+- Learn what an `Application Programming Interface` (API) is
+- Catch up on the `history of JavaScript`
+- Understand how to write more readable `asynchronous JavaScript`
+- Connect with different `public APIs`
+- Build a `Single Page Application` (SPA)
- Work with pre-existing code
-- Learn about Object-Oriented Programming
+- Learn about `Object-Oriented Programming`
## How to use this repository
-This repository consists of 3 essential parts:
+### Repository content
-1. `Reading materials`: this document contains all the required theory you need to know _**while**_ you're coding. It's meant as both study material and as a reference to understand what you're doing.
-2. `Homework`: this document contains the instructions for each week's homework.
-3. `Lesson Plans`: this part is meant for teachers as a reference. However, as a student don't be shy to take a look at it as well!
-
-After your first class you should start off with checking the `reading materials` for that week. At the beginning that would be the [Week 1 Reading](/Week1/README.md). Study all the concepts and try to get the gist of everything. After, you can get started with the `homework` for that week.
+This repository consists of 3 essential parts:
-If you have any questions or if something is not entirely clear ¯\\\_(ツ)\_/¯, please ask/comment on Slack!
+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
+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.
+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!
-## Before you start
+### How to study
-In the following weeks we will be using a `styleguide` to help you write _"clean code"_. What is a styleguide? Simply put, it's a set of design standards put in one collection. Companies create and use them to define their public identity (their "brand"). Watch the following to get a better idea:
+Let's say you are just starting out with the JavaScript3 module. This is what you do...
-- [Creating Your Company's Style Guide](https://www.youtube.com/watch?v=gv_wrrY70E0)
+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 `JavaScript3`, that would be [Week1 Reading](/Week1/README.md)
+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 JavaScript2 module)
+3. On **Friday** you start with the homework, found in the `MAKEME.md`. For the first week of `JavaScript3`, that would be [Week1 Homework](/Week1/MAKEME.md)
+4. You spend **Friday** and **Saturday** playing around with the exercises and write down any questions you might have
+5. **DEADLINE 1**: You'll submit any questions you might have before **Saturday 23.59**, in the class channel
+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
+7. You spend **Monday** and **Tuesday** finalizing your homework
+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
+9. Start the new week by going back to point 1!
-A styleguide is made by designers. In the case of website design, this styleguide is then handed over to developers to use when styling the frontend.
+In summary:
-The styleguide we'll be using is the one from Airbnb:
+
-- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
+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!
-While you do not need to read this guide in detail, it is recommended that you look at sections 1-8, 12-13, 15-21 and 23.
+### Video lectures
-The required packages you need to install in order to write code according to the styleguide are the following:
+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 [Stasel Seldin](https://hackyourfuture.slack.com/team/UQJGC1MSL): senior iOS developer!
-```json
-"eslint"
-"eslint-config-airbnb-base"
-"eslint-config-prettier"
-"eslint-plugin-import"
-"eslint-plugin-prettier"
-"prettier"
-```
+You can find out more about him here:
-They are already in this repository's `package.json` so all you have to do now to prepare is to execute the following command in your command line:
+- [GitHub](https://github.com/Stasel)
+- [@Stasel on Slack](https://hackyourfuture.slack.com/team/UQJGC1MSL)
-```md
-npm install
-```
+Learn from Stasel in the following playlist of videos he has made for you! (Click on the image to open the link)
-With this out of the way we can get started!
+
## Planning
| Week | Topic | Reading Materials | Homework | Lesson Plan |
| ---- | ------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------- | -------------------------------------- |
| 1. | Application Programming Interface (API), AJAX, Modules & Libraries | [Reading W1](/Week1/README.md) | [Homework W1](/Week1/MAKEME.md) | [Lesson Plan W1](/Week1/LESSONPLAN.md) |
-| 2. | Promises, Fetch API, JavaScript Versions, 'this' keyword, Arrow functions | [Reading W2](/Week2/README.md) | [Homework W2](/Week2/MAKEME.md) | [Lesson Plan W1](/Week1/LESSONPLAN.md) |
-| 3. | Object-Oriented Programming (OOP), ES6 Classes, Async/await, Thinking like a programmer III | [Reading W3](/Week3/README.md) | [Homework W3](/Week3/MAKEME.md) | [Lesson Plan W1](/Week1/LESSONPLAN.md) |
+| 2. | Promises, Fetch API, JavaScript Versions, 'this' keyword, Arrow functions | [Reading W2](/Week2/README.md) | [Homework W2](/Week2/MAKEME.md) | [Lesson Plan W1](/Week2/LESSONPLAN.md) |
+| 3. | Object-Oriented Programming (OOP), ES6 Classes, Async/await, Thinking like a programmer III | [Reading W3](/Week3/README.md) | [Homework W3](/Week3/MAKEME.md) | [Lesson Plan W1](/Week3/LESSONPLAN.md) |
| 4. | Final JavaScript Test | [Details](test.md) | - | - |
## Finished?
@@ -85,4 +128,4 @@ If you feel ready for the next challenge, click [here](https://www.github.com/Ha
_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 :)_
- This work is licensed under a Creative Commons Attribution 4.0 International License .
+ This work is licensed under a Creative Commons Attribution 4.0 International License .```
diff --git a/Week1/LESSONPLAN.md b/Week1/LESSONPLAN.md
index e69de29bb..a0d1c8f0e 100644
--- a/Week1/LESSONPLAN.md
+++ b/Week1/LESSONPLAN.md
@@ -0,0 +1,141 @@
+# Lesson Plan JavaScript3 Week 1
+
+## Agenda
+
+The purpose of this class is to introduce to the student:
+
+- What are `APIs` and how to interact with them
+- What is `AJAX` and how to apply it (`XMLHttpRequest`)
+- How to use libraries (`axios`)
+
+## Core concepts
+
+FIRST HALF (12.00 - 13.30)
+
+## 1. What are APIs and how to interact with them
+
+### Explanation
+- APIs are created by providers and used by consumers (BE provider, FE consumer)
+- Part of an application that can be communicated with from an outside source
+- Connect to it using "endpoints"
+- Software well-known APIs (Fb APIs, Twitter APIs, Maps APIs, weather APIs);
+- API doesn't care which language or technology is used in the consumer or the provider
+
+#### Types of APIs:
+- Private: for employees only under a company network for internal use.
+- Semi-private: for clients who paid for the API.
+- Public: for everyone on the web.
+
+#### Architecture styles of API:
+- Single purpose: API that gives a direct and specific service.
+- Aggregated API: one API as a wrapper for multiple APIs.
+- Web services API: punch of APIs working together to forma whole app.
+
+#### Basic structure of REST API
+
+- Endpoint: https://api.example.com
+- Endpoint with version: https://api.example.com/v1
+- Resources:
+* https://api.example.com/v1/users
+* https://api.example.com/v1/users/create
+* https://api.example.com/v1/users/1
+* https://api.example.com/v1/users/1/edit
+- Query params:
+* https://api.example.com/v1/users?limit=10
+### Example
+- Give real life example like (Devices like TV, any machine + electricity power socket interface which provides power to any external device)
+
+### Excercise
+
+### Essence
+- Mostly used to request data from some service
+- Communication between software and user needs UI interface but software and software needs API as an interface.
+
+## 2. What is `AJAX` and how to apply it (`XMLHttpRequest`)
+
+### Explanation
+- Before AJAX all page reload for all requests, via refreshing the url in the address bar with the new resource.
+- It's a technique, not a technology
+- `AJAX` stands for Asynchronous JavaScript and XML
+- Nowadays we use `JSON` instead of `XML`
+- Fetch data without reloading the page
+- The XMLHttpRequest API is defined in the browser (window.XMLHttpRequest)
+### Example
+Example using the XMLHttpRequest
+
+```javascript
+const oReq = new XMLHttpRequest();
+oReq.open('GET', `https://api.openweathermap.org/data/2.5/weather?q=${cityName}`);
+oReq.send();
+oReq.addEventListener('load', function (event) {
+ const data = JSON.parse(this.response);
+ if (data.cod >= 400) {
+ // error
+ console.log(data.message);
+ } else {
+ //success
+ console.log(data.coord.lat);
+ }
+});
+
+// or another way of getting data
+oReq.load = function (event) {
+ // use oReq.response or this.response
+ const data = JSON.parse(this.response);
+ if (data.cod >= 400) {
+ // error
+ console.log(data.message);
+ } else {
+ //success
+ console.log(data.coord.lat);
+ }
+};
+
+```
+
+### Excercise
+
+Steps of doing the following example:-
+** Install the live server plugin in VS (go to plugins -> live server -> install)
+1. Create self-invoked function to wrap your code
+2. Create an object instance of `XMLHttpRequest`
+3. Call the `open` function to fill it with the Request URL and the request Method
+4. Call the `send` function to make the request
+5. Add event listener with a callback for the sucess event `load`
+
+### Essence
+
+SECOND HALF (14.00 - 16.00)
+
+## 3. How to use libraries (`axios`)
+
+### Explanation
+- A library is a code solution a developer (or a team) has written to a common problem
+- Usually open-source
+- Helps to solve a problem within an application
+- Read the documentation on how to use it
+### Example
+Same example but using axios
+```javascript
+axios
+ .get(`https://api.openweathermap.org/data/2.5/weather?q=${cityName}`)
+ .then(function (response) {
+ // handle success
+ console.log(response.data);
+ }).catch(function (error) {
+ // handle error
+ console.log(error);
+ }).finally(function () {
+ // always be executed
+ console.log('I am always here')
+ });
+```
+
+> Note: Give example at the end with binding/showing these data in a DOM element like a
or a list instead of only showing them on the console using console.log.
+
+### Excercise
+### Essence
+
+
+
+
diff --git a/Week1/MAKEME.md b/Week1/MAKEME.md
index b14adadd4..6f040f6bc 100644
--- a/Week1/MAKEME.md
+++ b/Week1/MAKEME.md
@@ -15,47 +15,49 @@ This week's concepts can be challenging, therefore let's get an easy introductio
## **2. JavaScript exercises**
-> Inside of your `JavaScript3` fork and inside of the `Week1` folder, create a folder called `homework`. Inside of that folder, create a folder called `js-exercises`. For all the following exercises create a new `.js` file in that folder (3 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could be placeKitten.js.
+> Inside of your `JavaScript3` fork and inside of the `Week1` folder, create a folder called `homework`. Inside of that folder, create a folder called `js-exercises`. For all the following exercises create a new `.js` file in that folder (3 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could be `getRandomUser.js`.
-**Exercise 1: Place the kitten**
+**Exercise 1: Who do we have here?**
-Who doesn't love kittens on their screen?
+Wouldn't it cool to make a new friend with just the click of a button?
-Write an function that makes an API call to https://wwww.placekitten.com/api
+Write a function that makes a HTTP Request to `https://www.randomuser.me/api`
-- Inside the same file write two programs: one with `XMLHttpRequest`, and the other with `axios`
-- Each function should make an API call to the given endpoint: `https://wwww.placekitten.com/api`
+- Inside the JavaScript file write two functions: one with `XMLHttpRequest`, and the other with `axios`
+- Each function should make a HTTP Request to the given endpoint: `https://www.randomuser.me/api`
- Log the received data to the console
-- Incorporate error handling
+- Incorporate error handling: log to the console the error message
-**Exercise 2: Who do we have here?**
+**Exercise 2: Programmer humor**
-Wouldn't it cool to make a new friend with just the click of a button?
+Who knew programmers could be funny?
-Write a function that makes an API call to https://www.randomuser.me/api
+Write a function that makes a HTTP Request to `https://xkcd.now.sh/?comic=latest`
-- Inside the same file write two functions: one with `XMLHttpRequest`, and the other with `axios`
-- Each function should make an API call to the given endpoint: `https://www.randomuser.me/api`
+- Inside the same file write two programs: one with `XMLHttpRequest`, and the other with `axios`
+- Each function should make a HTTP Request to the given endpoint: `https://xkcd.now.sh/?comic=latest`
- Log the received data to the console
-- Incorporate error handling
+- Render the `img` property into an `
` tag in the DOM
+- Incorporate error handling: log to the console the error message
-**Exercise 3: Photo gallery**
+**Exercise 3: Dog photo gallery**
-Let's make a randomized photo gallery!
+Let's make a randomized dog photo gallery!
-Write a function that makes an API call to https://picsum.photos/400
+Write a function that makes a HTTP Request to `https://dog.ceo/api/breeds/image/random`. It should trigger after clicking a button in your webpage. Every time the button is clicked it should append a new dog image to the DOM.
- Create an `index.html` file that will display your random image
-- Write two programs: one with `XMLHttpRequest`, and the other with `axios`
-- Each function should make an API call to the given endpoint: `https://picsum.photos/400`
-- After receiving the data, render it to the page in a `
`
-- Incorporate error handling
+- Add 2 `
` and 1 `` element, either in the HTML or through JavaScript
+- Write two versions for the button functionality: one with `XMLHttpRequest`, and the other with `axios`
+- When any one of the 2 buttons is clicked it should make a HTTP Request to `https://dog.ceo/api/breeds/image/random`
+- After receiving the data, append to the `` a `` that contains an ` ` element with the dog image
+- Incorporate error handling: log to the console the error message
## **3. Code along**
Now that you've learned about APIs and how to connect with them, let's apply it in the context of a complete application.
-In the following application you'll be making an API call to an external, public API.
+In the following application you'll be making a HTTP Request to an external, public API. You'll use that data in order to fetch facts that you'll display in your own application: a Numbers Facts application.
Enjoy!
@@ -63,110 +65,60 @@ Enjoy!
## **4. PROJECT: Hack Your Repo I**
-In the following three weeks you are going to write a _Single Page Application_ (SPA) that makes use of the [GitHub API](https://developer.github.com/v3/guides/getting-started/).
-
-Figure 1 below shows an example of what your application will look like.
+In the following three weeks you are going to write an application that makes use of the [GitHub API](https://developer.github.com/v3/guides/getting-started/). Each week builds on top of the other, just like a real-world application!
-
+[](https://js3-spa.herokuapp.com/)
+Click on the image to open up the demo of the application!
-This application does 2 things:
+This application, HackYourRepo, does 2 things:
1. It makes connection to the GitHub API and retrieves all the repositories found in the [HackYourFuture account](https://www.github.com/hackyourfuture).
-2. It displays those repositories in an alphabetically-oreded list. When a user clicks on any of the repository names it will show more details about it.
-
-### Getting an overview
-
-For this week you're expected to build upon pre-existing code, found in the folder `homework`. Here's what you'll find:
-
-| Filename | Description |
-| ------------ | --------------------------------- |
-| `hyf.png` | Contains the HackYourFuture logo. |
-| `index.html` | The application's HTML file. |
-| `index.js` | A starter JavaScript file. |
-| `style.css` | A starter CSS file. |
-
-As you'll experience in your job, you'll be exposed to an already existing codebase. It's an essential skill to get used to doing this. But how?
-
-### A first examination
-
-1. Open `index.html` and examine its contents (but don't modify anything). Notice that the HTML `` looks like this:
-
- ```html
-
-
-
-
- ```
-
- The `` tag contains a single `` to which you will need to dynamically append HTML elements through your JavaScript code in `index.js`.
-
-2. Open `index.js`. This file contains a starter set of code for you to expand. It contains the following three functions:
-
- | Function | Description |
- | ----------------- | ------------------------------------------------------------------------------------------------------------ |
- | `fetchJSON` | Uses `XMLHttpRequest` to fetch JSON data from an API end point. This function uses an asynchronous callback. |
- | `createAndAppend` | A utility function for easily creating and appending HTML elements. |
- | `main` | Contains the start-up code for the application. |
-
- `index.js` also contains a variable with the URL required for fetching information about the HYF repositories:
-
- ```js
- const HYF_REPOS_URL =
- 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
- ```
-
-3. Open the `index.html` file in your browser. You will see an unordered list with the names of the HYF repositories.
-
-4. Review the `main()` function in `index.js` and examine how this code fetches the JSON data and calls renders the data as unordered list in the web page.
-
-5. Take a look at the API URL:
-
-```
-https://api.github.com/orgs/HackYourFuture/repos?per_page=100
+2. It displays those repositories in an alphabetically-ordered list. When a user clicks on any of the repository names it will show more details about it.
+
+In the course of the next 3 weeks you'll be writing the necessary code to make all of this work!
+
+### 4.1 Requirements
+
+To get started, make sure you're in the right GIT branch: `week1-[YOURNAME]`. Then, navigate to the `hackyourrepo-app` folder and become familiar with the files there.
+
+This week you're required to (1) setup the HTML structure of the application. In addition, you are expected to (2) style the application to make it user-friendly.
+
+Here are the requirements for the HTML:
+
+- Include 3 `
` tags
+- Include a `` tag
+- Use the following placeholder data:
+
+```js
+const placeholderRepos = [
+ {
+ name: 'SampleRepo1',
+ description: 'This repository is meant to be a sample',
+ forks: 5,
+ updated: '2020-05-27 12:00:00',
+ },
+ {
+ name: 'AndAnotherOne',
+ description: 'Another sample repo! Can you believe it?',
+ forks: 9,
+ updated: '2020-05-27 12:00:00',
+ },
+ {
+ name: 'HYF-Is-The-Best',
+ description:
+ "This repository contains all things HackYourFuture. That's because HYF is amazing!!!!",
+ forks: 130,
+ updated: '2020-05-27 12:00:00',
+ },
+];
```
-This URL is special, as it gives us data in JSON format (Try it out in your browser!). This type of URL is also known as an `endpoint`, an address that we can use to send a request to in order to get data. Learn more about endpoints [here](https://smartbear.com/learn/performance-monitoring/api-endpoints/).
-
-Note the query string `?per_page=100` in the above URL. If you don't specify this `query string` you will only get the first 30 repositories (the default `per_page` is 30, which we know because it says so in the [API documentation](https://developer.github.com/v3/#pagination)).
-
-### Week 1 Assignment
-
-The assignment for this week is to produce a functional application that looks similar to Figure 1:
-
-
-
-Functionally, the application should do the following:
-
-1. Make an API call to the endpoint: https://api.github.com/orgs/HackYourFuture/repos?per_page=100
-2. Display the first 10 items in the HTML file (write JavaScript to add element to the DOM)
-3. Show feedback when an error has happened
-
-Modify the following files:
-
-**1. `index.js`**
-
-- Add new functions and modify function `main()` as you see fit.
-- Render network errors to the DOM (see Figure 2 below for an example). Do not use `console.log` as regular users will not see the console output. Instead, create an element that displays the error message in the DOM. Use the predefined `alert-error` class from `style.css` to style your error. It should look like this:
-
-
-
-Figure 2. Rendering of network errors.
-
-**2. `style.css`**
-
-- Add your own CSS styling. Use `style.css` for all of your CSS rules to style the `index.html`. Make sure your UI is responsive. Try it with Chrome Developer Tools in the browser, using a mobile phone format and a tablet format, portrait and landscape.
-
- **You are not allowed to use a CSS library such as Bootstrap.**
-
-**Hints:**
-
-- To sort the list repositories use [`.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) and [`.localeCompare()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare).
-
-- Use CSS media queries, percentage values and [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) to make the UI responsive.
+Here are the requirements for the CSS:
-- To force a `404` network error so that you can test the rendering of errors, change the URL to make an invalid GitHub request, e.g. append an `x` to `orgs`: `orgsx`.
+- Make use of `flexbox`
+- Make use of `media-queries` and `calc()` to make the page responsive ([mobile, tablet, desktop](https://tinyurl.com/yc5zmste))
-Good luck!
+Other than this you can create your own version of the page!
## **SUBMIT YOUR HOMEWORK!**
@@ -175,7 +127,7 @@ After you've finished your todo list it's time to show us what you got! The home
1. JavaScript exercises
2. PROJECT: HackYourRepo I
-Upload both to your forked JavaScript3 repository in GitHub. Make a pull request to your teacher's forked repository.
+Upload both to your forked JavaScript3 repository in GitHub. Make a pull request to the HackYourHomework forked repository.
> Forgotten how to upload your homework? Go through the [guide](../hand-in-homework-guide.md) to learn how to do this again.
diff --git a/Week1/README.md b/Week1/README.md
index a48540bf0..2b9536d3b 100644
--- a/Week1/README.md
+++ b/Week1/README.md
@@ -9,6 +9,7 @@ These are the topics for week 1:
- Connecting with APIs
2. Asynchronous JavaScript and XML (AJAX)
- JavaScript Object Notation (JSON)?
+ - Stringifying and parsing JSON
- XMLHttpRequest (XHR)
3. Modules & Libraries
- What's a module?
@@ -16,119 +17,249 @@ These are the topics for week 1:
- An example of a library
- How to use a library
+## 0. Video Lectures
+
+Your teacher Stasel has made video lectures for this week's material. You can find them here: [Videos 1 - 5](https://www.youtube.com/playlist?list=PLVYDhqbgYpYVchJ9QQ3rC2WxYKrOiceYX)
+
+
+
## 1. Application Programming Interface (API)
-Whenever we talk development we'll inevitably end up talking about Application Programming Interfaces, or APIs for short. But what is all the fuss about?
+Whenever we talk about software development, we'll inevitably end up talking about `Application Programming Interfaces`, or APIs for short. But what is all the fuss about?
The first thing we need to understand is that API means different things to different people. Some people use it to refer to a complete application (frontend + backend), others use it to only refer to the server, or there's even people who use it to refer to any part of an application (i.e. "frontend API"/"server API")
For our purposes it's useful to stick to one definition, while keeping in mind that others will use it differently. Here's the definition we'll use:
```markdown
-An API is any software that contains a part that's accessible from an outside source: i.e. open to requests from the client (whether it's a from a frontend or another server). That part that's accessible is the "interface" of that software.
+An Application Programming Interface (API) is an interface to an application. It's the point of connection for any other application, in order to communicate with it. The API defines the terms of how to connect to it.
```
-You can think of an API in the following manner: Imagine you want to rent out a room in your house through Airbnb. Everyone who has a key to this room can freely enter and make use of whatever is inside. In this analogy the house is the API, while the room that's rented out is the "interface".
+You can think of an API as a wall socket:
+
+
+
+As you can see on the image, the wall socket has a certain shape. This shape defines in what way something can connect to it. If you were to use a plug that had a different shape, it would never fit and thus never be able to connect. But if you had a plug that was in the correct shape, you got plug it in and proceed to connect to whatever is behind the socket (which in this case is the service of electricity).
+
+In a way, you could say that an API is the frontend to an application. It's similar to the frontend part of a website. The biggest difference is, however, that instead of giving a way for human users to interact with it, an API gives a way for other applications to interact with it.
For more research, check out the following resources:
+- [APIs Are Like User Interfaces - Just With Different Users in Mind](https://www.programmableweb.com/news/apis-are-user-interfaces-just-different-users-mind/analysis/2015/12/03)
- [What are APIs - series](https://www.youtube.com/watch?v=cpRcK4GS068&list=PLcgRuP1JhcBP8Kh0MC53GH_pxqfOhTVLa)
+- [APIs for Beginners](https://www.youtube.com/watch?v=GZvSYJDk-us)
### Public/private APIs
There are 2 different types of APIs: **public** and **private** APIs.
-An API is **public** when software companies publish parts of their software to be freely used by developers from the outside world. If you were to integrate the Facebook API as a login sytem in your application, you would be using their API as a public API.
+An API is **public** when software companies publish parts of their software to be freely used by developers from the outside world. If you were to integrate the Facebook API as a login system in your application, you would be using their API as a public API.
Conversely, there are also **private** APIs: software companies that grant access to parts of their backend applications to internal developers only, in order to develop new services to be used either internally or for the outside world.
-In reality, there are way more private than public APIs. This is because it's usually in the company's best interest to keep their code base hidden from the public eye: it would be like giving your secret recipe away for nothing.
+In reality, there are way more private than public APIs. This is because it's usually in the company's best interest to keep their code base hidden from the public eye: it would be like giving your secret recipe away for free.
-Keep this in mind: **in the real world programming is a means to serving a business end**. In this course you're learning how to program, to make nice-looking functional applications. However, this is always done within a business context. This is to say: does this software lead to making more money/gaining more popularity/or the achievement of any other business goal?
+Keep this in mind: in the real world **programming is only a means to serving a business end**. In this course you're learning how to program, to make nice-looking, well-functioning applications. However, this is always done within a business context. This is to say: does this software lead to making more money/gaining more popularity/or the achievement of any other business goal?
- [The Business Impact of Private, Partner and Public APIs](https://www.youtube.com/watch?v=Bk50AYGvs-g)
### Connecting with APIs
-A big part of what applications do is **moving data from one place to another**. Let's say you are on the HackYourFuture website and feel like donating some money. First of all, that's very nice of you! You head out to the website and click on the donate button. You type in the amount and click on "donate". You'll notice you immediately get redirected to a different website, namely Mollie.com. How did Mollie know how to do this?
+A big part of what applications do is **moving data from one place to another**. Let's say you are on the HackYourFuture website and feel like donating some money. First of all, that's very nice of you! You head out to the website and click on the donate button. You type in the amount and click on "donate". You'll notice you immediately get redirected to a different website, namely checkout.stripe.com. How did Stripe know how to do this?
+
+It's because the HackYourFuture website sends a **HTTP Request** to Stripe. The request basically says "Hey Stripe, some user from the HackYourFuture site wants to make a digital payment, can you handle that?". As a response Stripe answers "Of course, send the user to this specific URL and I'll take it from there!".
+
+> Anytime a request to an API is made this is called a `HTTP Request`. However, in practice people use different terms for the same thing. Synonyms for `HTTP Request` are `API call/request`, `Network call/request`, `Web request/call` or`HTTP call`. Which do you prefer?
+
+A HTTP Request has to be made using a special method. The browser gives us two of them: `XMLHttpRequest` and `Fetch API`. `XMLHttpRequest` (or XHR for short) is the older, more verbose method. It looks like this:
+
+```js
+// 1. Create a new XMLHttpRequest object
+const xhr = new XMLHttpRequest();
+
+// 2. Configure it: GET-request for the URL /article/.../load
+xhr.open('GET', '/article/xmlhttprequest/example/load');
+
+// 3. Send the request over the network
+xhr.send();
+
+// 4. This will be called after the response is received
+xhr.onload = function() {
+ if (xhr.status != 200) {
+ // analyze HTTP status of the response
+ alert(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
+ } else {
+ // show the result
+ alert(`Done, got ${xhr.response.length} bytes`); // response is the server
+ }
+};
+
+xhr.onprogress = function(event) {
+ if (event.lengthComputable) {
+ alert(`Received ${event.loaded} of ${event.total} bytes`);
+ } else {
+ alert(`Received ${event.loaded} bytes`); // no Content-Length
+ }
+};
+
+xhr.onerror = function() {
+ alert('Request failed');
+};
+```
-It's because the HackYourFuture website sends an **API call** to Mollie. The request basically says "Hey Mollie, some user from the HackYourFuture site wants to make a digital payment, can you handle that?". As a response Mollie answers "Of course, send the user to this specific URL and I'll take it from there!".
+This way of making HTTP Requests is outdated (and not recommended to use), but it's good to be aware of it as you might still see it in old code bases.
-> Anytime a request to an API is made this is called an `API call`. However, in practice people use different terms for the same thing. Synonyms for `API call` are `API request`, `Network call/request` or`HTTP call/request`. Which do you prefer?
+The newer way of making HTTP Requests involves using the `Fetch API`. You'll learn more about that next week!
-For further study of how to make API calls, check out the following resources:
+For further study of how to make HTTP Requests, check out the following resources:
- [Working with APIs in JavaScript](https://www.youtube.com/watch?v=ecT42O6I_WI)
- [Making HTTP Requests in JavaScript](https://www.kirupa.com/html5/making_http_requests_js.htm)
## 2. Asynchronous JavaScript and XML (AJAX)
-AJAX is the idea that data can be loaded into a webpage without refreshing the entire website. The term is an acronym for `asynchronous JavaScript and XML`. Let's pick that apart:
+AJAX is the idea that data can be loaded into a webpage without refreshing the entire website. It's a **web development technique** when building websites, NOT a technology or programming language.
-- Asynchronous JavaScript refers to the fact that an asynchronous function is used. As we've learned in the previous module, an asynchronous function allows the browser to do multiple things simultaneously.
+The term is an acronym for `asynchronous JavaScript and XML`. Let's pick that apart:
+
+- Asynchronous JavaScript often refers to the act of using an asynchronous function to make an HTTP Request to fetch data. As we've learned in the previous module, an asynchronous function allows the browser to do multiple things simultaneously. In this way we fetch data in the background, while the user is still able to navigate the webpage.
- XML is a data format used to send information from a server to a client, and vice versa.
-The name AJAX is actually a misnomer, because XML isn't really used any more. Instead, another data format has taken its place: `JSON`.
+This technique was used back in the days when the web wasn't that advanced. Back then we used XML is the standard format we used to structure our data in. Nowadays we have replaced it with another data format: `JSON`.
+
+### JavaScript Object Notation (JSON)
+
+`JSON` stands for JavaScript Object Notation and is a very JavaScript-like data format. Here's a small example:
+
+```json
+{
+ "first name": "Noer",
+ "last name": "Paanakker",
+ "age": 28,
+ "address": {
+ "street address": "Strekkerweg 79",
+ "city": "Amsterdam",
+ "postal code": "1033 DA"
+ }
+}
+```
+
+If you look closely it almost looks exactly like a regular JavaScript object. There are 2 big differences: (1) in a JSON object everything is turned into a string (als known as "stringified"), and (2) it's not tied to the JavaScript language. Actually, many other languages can work with JSON!
+
+In AJAX we make a HTTP Request to a web server, that then responds back with information to be used in the frontend. Generally speaking, this data will be send in `JSON` format. The web server "stringifies" (makes into a string) the data to be send first before it sends it.
+
+### Stringifying and parsing JSON
-### JSON
+JSON is the modern web standard data format to send and receive data in. In order to make something into JSON format we need to `stringify` it: make the whole object into one string. Luckily, JavaScript gives us a way to do this:
-In AJAX we make a client request to a web server, that in response sends us back information to be used in the frontend. Generally speaking, this data will be send in `JSON` format.
+```js
+const noer = {
+ firstName: 'Noer',
+ lastName: 'Paanakker',
+};
+
+const noerJSON = JSON.stringify(noer);
+
+console.log(noerJSON); // Result: {"firstName":"Noer","lastName":"Paanakker"}
+```
+
+Here's another way of looking at the "stringifying" process: let's say you want to send your mother a gift, a brand new HackYourFuture T-shirt. Would you just put the shirt right into the mailbox, like that? Of course not! You would wrap it up nicely and put it into a box. Then you put it in the mailbox and off it goes!
+
+This act of putting something into a box is what's happening when we `stringify` data (either on the client-side or server-side).
+
+After the JSON data has been send, the receiver has to be able to interpret it. This process of making JSON interpretable by the programming language within that environment is called `parsing`. As we're using JavaScript, it doesn't seem like a big stretch. But what if we're using some other programming language like Python or Java?
+
+To follow our analogy, this is basically your mother unpacking her T-shirt from out of the box you put it in!
+
+Again, in JavaScript we can use another method gained from the global `JSON` object in order to `parse` our JSON data:
+
+```js
+const noer = {
+ firstName: 'Noer',
+ lastName: 'Paanakker',
+};
-So, technically speaking, the term would actually be AJAJ. However, the industry has decided to stick with the term AJAX to refer to these processes.
+const noerJSON = JSON.stringify(noer);
+const noerParsed = JSON.parse(noerJSON);
+
+console.log(noerParsed); // Result: { firstName: 'Noer', lastName: 'Paanakker' };
+```
+
+Nowadays we use JSON to perform asynchronous operations using JavaScript. So, technically speaking, the term would actually be AJAJ. However, the industry has decided to stick with the term AJAX to refer to these processes. Keep that in mind whenever someone asks you about it!
+
+Go through the following to learn more about JSON and AJAX:
+
+- [JSON - Introduction](https://www.w3schools.com/js/js_json_intro.asp)
+- [Learn JSON in 10 Minutes](https://www.youtube.com/watch?v=iiADhChRriM)
- [JSON Crash Course](https://www.youtube.com/watch?v=wI1CWzNtE-M)
### XMLHttpRequests (XHR)
-In order to make an AJAX request we have to make use of a special type of object, called `XMLHttpRequest`(shortened to XHR). It's an object predefined for us by the `window` object in the browser.
+Traditionally, in order to make use of the AJAX technique we need to make use of a special type of object, called `XMLHttpRequest`(shortened to XHR). It's an object predefined for us by the `window` object in the browser.
> The `window` object is the most top-level object available to us in the browser. It contains the `document`, which contains all the HTML/CSS and JavaScript we write. Besides this, the `window` also contains a lot of other things we use when writing frontend code: `setTimeout()`, `alert()` and it even contains a reference to the `console` (from which we get `console.log()`). Try it out in the console if you want to see for yourself!
-By creating a new instance of this object we can start making AJAX requests!
+By creating a new instance of this object we can start making HTTP requests!
```js
const xhr = new XMLHttpRequest();
```
-Making XHR requests is the primary way of making API calls. It allows us to send and retrieve data from other services.
+Making XHR requests is the primary way of making HTTP Requests. It allows us to send and retrieve data from other services.
+
+However, this method is outdated and we use more modern means now (using the `Fetch Web API` or a solution like `axios`). You will learn about that next week!
Check the following resources to learn more about XHR.
- [XMLHttpRequest](https://github.com/hackyourfuture/fundamentals/blob/master/fundamentals/XMLHttpRequest.md)
- [AJAX Crash Course](https://www.youtube.com/watch?v=82hnvUYY6QA)
-- [Sending JavaScript Http Requests with XMLHttRequest](https://www.youtube.com/watch?v=4K33w-0-p2c)
+- [Sending JavaScript HTTP Requests with XMLHttRequest](https://www.youtube.com/watch?v=4K33w-0-p2c)
## 3. Modules & Libraries
### What's a module?
-A `module` is a part of a program that contains one or more functionalities. For example, a single function that has only 1 job could be considered a module. When developing applications you'll always be writing multiple functionalities in order for your software to work as expected. These can be written all in one file, and it would fine. The browser/operating system would be able to interpret and execute it anyway. But for you, the human, it's very hard to keep overview of what is happening at what level of the application.
+A `module` is a part of an application that contains usually a single functionality. For example, a single function that has only 1 job could be considered a module. For example:
+
+```js
+function addNums(num1, num2) {
+ return num1 + num2;
+}
+```
+
+If this little function has its own dedicated `.js` file and you can import it into another file, it's a module!
+
+When developing applications you'll always be writing multiple functionalities in order for your software to work as expected. These can be written all in one file, and that would still work. The browser/operating system would be able to interpret and execute it anyway. But for you, the human, it's very hard to keep overview of what is happening at what level of the application. Can you only imagine having to look through one big file of 1000's of lines of code, just to find
-In order to keep a better overview, we can choose to **modularize** our application: split it up into smaller parts that, in theory, all work independently.
+In order to keep a better overview, we can choose to **modularize** our application. This means: splitting it up into smaller parts (modules) that, in theory, all work independently.
However, creating better overview is not the only reason. Among other reasons, modules make a developer's job easy by:
-- Allowing them to focus on only one area of the functionality of the software application
-- Isolating individual blocks of code, in case anything breaks
+- Making the application easier to maintain, by making it more readable and thus easier to modify
+- Isolating individual blocks of code, in order to make errors more easily traceable
- Encouraging the developer to write code in a way that makes it reusable
For more information about this, go through the following:
+- [Introduction to Modular Design](https://www.youtube.com/watch?v=20JP8w6_nVA)
+- [JavaScript Patterns: The Traditional Module Pattern](https://www.youtube.com/watch?v=SKBmJ9P6OAk)
+- [JavaScript Modules in 100 Seconds](https://www.youtube.com/watch?v=qgRUr-YUk1Q)
- [JavaScript Modules: From IIFEs to CommonJS to ES6 Modules](https://www.youtube.com/watch?v=qJWALEoGge4)
### What's a library?
If you've ever written code you know how easy it is to duplicate it: you just copy and paste it.
-Modules are small blocks of code that make up a functionality. But what if you have a bunch of modules that collectively aim to solve a bigger problem, like creating a [Single Page Application](https://en.wikipedia.org/wiki/Single-page_application)?
+Modules are small blocks of code that make up a functionality. But what if you have a bunch of modules that collectively aim to solve a bigger problem, like creating [data visualizations](https://d3js.org/) or make DOM manipulation easier ([jQuery](https://jquery.com/))?
-For this we use a `library`: a set of code that a developer (or a team of developers) has written in order to solve these bigger problems within an application. A library, typically, contains a collection of modules that work together to solve a big problem.
+For this we use a `library`: code that a developer (or a team of developers) has written in order to solve these bigger problems within an application. A library, typically, contains a collection of modules that work together in order to solve a bigger problem.
-> Like many things in programming, people use various terms to describe the same thing. In the case of `library`, you'll often hear it spoken of as `package` or `namespace`.
+> Like many things in programming, people use various terms to describe the same thing. In the case of `library`, you'll often hear it spoken of as `package`, `namespace` or `dependency`.
Why do we use libraries? We use them to help us make building applications easier. Think of it like building a house: in theory you could do it all by hand. But as you can imagine, this is highly inefficient and time-consuming. So instead we use tools to help us out. These can be small tools (like a hammer or screwdriver) or bigger ones (like a concrete mixer or wheel barrow).
-In the real-world companies use libraries all the time. They either make them themselves, or they make use of public ones. If the original developers of a library have published their code, through a platform like [npmjs.com](https://www.npmjs.com/) for example, it can legally be used in custom applications. This is called **open-source**: the source code is open for any to look into, use and modify to their own needs.
+In the real-world developers use libraries all the time. They either make them themselves, or make use of public ones. If the original developers of a library have published their code, through a platform like [npmjs.com](https://www.npmjs.com/) for example, it can legally be used in custom applications for free. This is called **open-source**: the source code is open for any to look into, use and modify to their own needs.
Examples of common JavaScript libraries are the following:
@@ -145,11 +276,13 @@ When researching these it's important to ask yourself two questions:
For further study, check the following:
+- [Code Libraries](https://www.youtube.com/watch?v=FQAQTXE_vt4)
- [JavaScript Libraries](https://www.youtube.com/watch?v=uq7omoxwA7A)
+- [https://www.youtube.com/watch?v=24GF5MVEEjE](https://www.youtube.com/watch?v=24GF5MVEEjE)
### An example of a library
-In a previous section we discussed APIs and the importance of being able to make API calls. We have seen that we can use the XHR object to do so. In this section we'll discuss a `library` that makes this process easier for us. It's called [axios](https://github.com/axios/axios), a JavaScript library that allows us to make API calls in an easier way.
+In a previous section we discussed APIs and the importance of being able to make HTTP Requests so that we can communicate with them. We have seen that we can use the `XHR` object to do so. In this section we'll discuss a `library` that makes this process easier for us. It's called [axios](https://github.com/axios/axios), a JavaScript library that allows us to make HTTP Requests in an easier way.
Here's what it looks like in action:
@@ -172,11 +305,11 @@ axios
Any library that exists is developed to solve some problem. The main problems `axios` aims to solve are the following:
1. how to make an `HTTP request` in an easier way
-2. how to write more readable asynchronous code.
+2. how to write more readable asynchronous code
Here's how `axios` solves problem 1:
-- It abstracts away/"simplifies")the XHR logic needed to make an API call and wraps it inside of functions that are more descriptive (like `axios.get` or `axios.post`, to indicate a GET and POST request)
+- It abstracts away/simplifies the XHR logic needed to make a HTTP Request and wraps it inside of functions that are more descriptive (like `axios.get` or `axios.post`, to indicate a GET and POST request)
Here's how `axios` solves problem 2:
@@ -186,7 +319,7 @@ Here's how `axios` solves problem 2:
Now that you've learned about the utility of libraries, let's talk a little about how to approach using a library. Keep in mind that this is not the only way to do it, but it will set you off on a good start.
-1. **Do your research**. Doing research means finding out more about the library. Is it new? Is it fully functional? What do other people say about using it? Is it backed by the community? Does the library have a GitHub page?
+1. **Do your research**. Doing research means finding out more about the library. Is it new? Is it fully functional? What do other people say about using it? Is it backed by a sizable developer community? Does the library have a GitHub/NPM page?
2. **Read the documentation**. If code has been published for everyone to use, most likely the developers have written a guide on how to use it. This is called `documentation`. After doing your research delve into it and try to figure out what the philosophy and usages of the library are.
3. **Try out a basic example**. A basic example can usually be found in the documentation. Copy and paste it into an empty file for yourself and try it out. It's best to try it out in isolation first, so that you can learn exactly what makes it work. Then slowly start playing around with it: change names, move lines of code.
4. **Try to integrate it with your own code base**. Once you've tried it out it's time integrate it into your own code. Figure out where to best put it. The documentation can help you out with that. Look at other developer's code and see how they use it. Watch videos or read articles online.
diff --git a/Week1/assets/hyf-github.png b/Week1/assets/hyf-github.png
index 393bc0288..eef2e9692 100644
Binary files a/Week1/assets/hyf-github.png and b/Week1/assets/hyf-github.png differ
diff --git a/Week2/LESSONPLAN.md b/Week2/LESSONPLAN.md
index e69de29bb..59587c5f4 100644
--- a/Week2/LESSONPLAN.md
+++ b/Week2/LESSONPLAN.md
@@ -0,0 +1,462 @@
+# Lesson Plan JavaScript3 Week 2
+
+## Agenda
+
+The purpose of this class is to introduce to the student:
+
+- How to use the `fetch` API to do AJAX calls
+- The structure and use of `Promises`
+- The `this` keyword and its relationship with `scope`
+
+## Core concepts
+
+FIRST HALF (12.00 - 13.30)
+
+## 1. Promises
+
+### Explanation
+- JS versions https://www.w3schools.com/js/js_versions.asp
+ - the javascript language evolves, new things are added and some thing become obsolete
+- It's a way to introduce asynchronicity to your application
+- Makes asynchronous code read like it's synchronous
+
+
+In the examples `setTimeout` is used to illustrate asynchronous code. In the real world there will be some code doing useful work here, for example `fetch`.
+
+**Callback**
+```javascript
+let didFinishHomework = true;
+let doHomeWork = function (cb) {
+ setTimeout(function () {
+ if ( didFinishHomework )
+ cb(null); // call callback function with NO error and no data
+ else
+ cb(new Error('homework not done, too lazy')); // call callback function with error
+ }, 1000);
+}
+
+
+doHomeWork(function (err) {
+ if ( err )
+ console.warn(err.message);
+ else
+ console.log('home work is done now');
+})
+```
+
+**Promise**
+```javascript
+let didFinishHomework = true;
+let promiseToDoHomeWork = new Promise(function (resolve, reject) {
+ setTimeout(function () {
+ if ( didFinishHomework )
+ resolve(); // goto then
+ else
+ reject(new Error('homework not done, too lazy')); // goto catch and pass the error
+ }, 1000);
+});
+
+promiseToDoHomeWork
+ .then(function () { console.log('home work is done now'); })
+ .catch(function (err) { console.warn(err); })
+
+```
+
+**!!! Students should watch this video !!!**
+- https://youtu.be/RvYYCGs45L4
+
+
+### Example
+
+#### Nested callback/promises example
+
+```javascript
+let attendClass = function (cb) {
+ setTimeout(function () {
+ if ( true )
+ cb(null, 'I attend the class'); // call the callback function with no Error and some data
+ else
+ cb(new Error('class not attended, stayed home')); // call the callback function with an Error
+ }, 1000);
+}
+
+let didFinishHomework = true;
+let doTheHomeWork = function (message, cb) {
+ setTimeout(function () {
+ if ( didFinishHomework )
+ cb(null, message + ' then I did the homework'); // call the callback function with no Error and some data
+ else
+ cb(new Error('homework not done, was lazy')); // call the callback function with an Error
+ }, 1000);
+}
+
+let submitHomeWork = function (message, cb) {
+ setTimeout(function () {
+ if ( true )
+ cb(null, message + ' so I submit my homework'); // call the callback function with no Error and some data
+ else
+ cb(new Error('homework not submited, github is down')); // call the callback function with an Error
+ }, 1000);
+}
+
+// call attendClass, after it is finished call doTheHomeWork then submitHomeWork. In each step pass the output of the previous step. In case of an error show it in the console
+
+attendClass(function (err, data) {
+ if ( err )
+ console.warn(err.message);
+ else
+ doTheHomeWork(data, function (err1, data1) {
+ if ( err1 )
+ console.warn(err1.message);
+ else
+ submitHomeWork(data1, function (err2, data2) {
+ if ( err2 )
+ console.warn(err2.message);
+ else
+ console.log(data2)
+ });
+ })
+})
+```
+Mention how this nested structure is hard to understand and read. Multiple variables with similar names and error handling is all over the place.
+Simulate an error in doTheHomeWork by setting `didFinishHomework = false` and run the example again
+
+```javascript
+
+let attendClass = function () {
+ return new Promise(function (resolve, reject) {
+ setTimeout(function () {
+ if ( true )
+ resolve('I attend the class'); // goto then and pass the data
+ else
+ reject(new Error('class not attended, stayed home')); // goto catch and pass the error
+ }, 1000);
+ });
+}
+
+let didFinishHomework = true;
+let doTheHomeWork = function (message) {
+ return new Promise(function (resolve, reject) {
+ setTimeout(function () {
+ if ( true )
+ resolve(message + ' then I did the homework'); // goto then and pass the data
+ else
+ reject(new Error('homework not done, was lazy')); // goto catch and pass the error
+ }, 1000);
+ });
+}
+
+let submitHomeWork = function (message) {
+ return new Promise(function (resolve, reject) {
+ setTimeout(function () {
+ if ( true )
+ resolve(message + ' so I submit my homework'); // goto then and pass the data
+ else
+ reject(new Error('homework not submited, github is down')); // goto catch and pass the error
+ }, 1000);;
+ });
+}
+
+attendClass()
+ .then(function (result) {
+ return doTheHomeWork(result);
+ })
+ .then(function (result) {
+ return submitHomeWork(result);
+ })
+ .then(function (result) {
+ console.log(result);
+ })
+ .catch(function (error) { // catches all errors
+ console.warn(error.message);
+ });
+
+
+```
+Simulate an error in doTheHomeWork by setting `didFinishHomework = false` and run the example again.
+
+- Promise.all
+
+Imagine that you are cleaning your house. If you are going to to it alone then it will take you the whole day. However if you ask your friend to help then you can be done in half the time.
+
+```javascript
+Promise.all([cleanKitchen("Me"), cleanBathroom("friend")]).then(function ([res1, res2]) { console.log('all finished') });
+```
+
+- Promise.race
+
+Sometimes I get really hungry. Then I want to eat as soon as possible. So I order a pizza. But I never know how long it will take for the pizza to arrive. And I am really hungry. So I start frying some potatotes. When at one of them is ready either the pizza has arrived or the frites are done then I will eat and I do not have to wait for the other one.
+
+```javascript
+Promise.race([fryPotatoes(), orderPizza()]).then(function (food) { console.log('I am eating: '+food) });
+```
+
+### Exercise
+
+#### Easy exercise (see difficult exercise alternative below)
+
+**Part 1**
+Rewrite the following code to use promise instead of callbacks. *As preparation for `fetch`*
+
+```javascript
+{
+const WEATHER_URL = `https://api.openweathermap.org/data/2.5/weather?q=amsterdam&appid=316f8218c0899311cc029a305f39575e`;
+
+function fetchResourceAsCallback(url, cb) {
+ const oReq = new XMLHttpRequest();
+ oReq.open('GET', url);
+ oReq.send();
+ oReq.addEventListener('load', function (event) {
+ const response = JSON.parse(this.response);
+ if (response.code >= 400) {
+ // error
+ cb(new Error("Failed to get because:"+response));/´// call callback function with an error
+ } else {
+ //success
+ cb(null, response); // call callback function with NO error and pass the response
+ }
+ });
+}
+
+fetchResourceAsCallback(WEATHER_URL,
+ function (err, data) {
+ if ( err )
+ console.warn(err.message);
+ else
+ console.log(data);
+ }
+);
+
+function fetchResourceAsPromise(url) {
+ // your code goes in here
+}
+
+fetchResourceAsPromise(WEATHER_URL)
+.then(function (result) {
+ console.log(result);
+})
+.catch(function (err) {
+ console.warn(err.message);
+});
+}
+
+```
+
+**Part 2**
+
+Use `Promise.all` to load data for multiple cities in parallel. Ask students to discuss in which scenarios it would be better to load data in parallel. In what scenarios is loading data in parallel not better.
+
+```javascript
+
+const URLS_TO_LOAD = [ 'https://samples.openweathermap.org/data/2.5/weather?q=London&appid=316f8218c0899311cc029a305f39575e', 'https://api.openweathermap.org/data/2.5/weather?q=amsterdam&appid=316f8218c0899311cc029a305f39575e'];
+```
+
+* Hint: use `map` to convert from an array of URLs to an array of promises.
+
+**Alternative exercise - Cooking pasta**
+
+**❗❗❗ Difficult exercise ❗❗❗**
+
+> Async can be hard to understand without real live example. Cooking is a great example of mixed synchronous and asynchronous tasks. In this assignment we'll cook pasta with promises 💍
+
+
+Let's say we want a program to cook some pasta. Some of the steps involved in cooking pasta are:
+
+1. Gathering the ingredients (pasta, garlic, tomatoes, sage, butter)
+2. Cutting the garlic
+3. Cutting the tomatoes
+4. Cooking the water
+5. Cooking the pasta
+6. Baking the garlic
+7. Baking the tomatoes
+ X. Mixing the pasta with sauce
+
+If we do this synchronously there is no chance of it becoming a good meal because the pasta would be cold by the time the vegetables are ready. It would also take way too long this way. So let's fix that!
+
+1. Think about how to do this asynchronously; which tasks could be run at the same time? What steps should wait for what other steps? Try to write down a basic recipe (don't write any code yet!)
+2. Now convert your recipe to pseudocode (in markdown). The point is to name functions and show which functions call which other functions. The logic should be there but we'll write the code in the next step.
+3. Write the actual code using promises. Add timeouts to each task (estimate how many minutes a task would take and then set the timeout to that many seconds so 8 minutes for cooking pasta would be 8 seconds in your programme)
+4. Can you get the code to work like you would cook pasta in the kitchen? Try using Promise.all if you want to wait for several tasks to finish.
+
+
+
+> Async await really helps simplify asynchronous (promisified) code. The previous example can be improved by applying it.
+
+5. Try rewriting your previous attempt using Async/Await. ⏰🍝⏰
+
+
+
+### Essence
+
+- It's the accepted solution to [callback hell](http://callbackhell.com/)
+- in terms of features it does not offer something new, everything one can do with promises could also be done with callbacks but it is easier to write and read the code when promises are used
+
+## 2. How to use the `fetch` API to do AJAX calls
+
+### Explanation
+- Modern replacement of XMLHttpRequest
+- Uses Promise structure
+- The Fetch API is defined in the browser (window.fetch)
+- Only modern browsers support it (show [caniuse.com](https://caniuse.com/#feat=fetch))
+- Fetch API documentations by mozilla [link](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
+### Example
+
+### Excercise
+```
+fetch('https://seriousnews.com/api/headlines')
+ .then(function (response) {
+ response.json();
+ }).then(headlines => {
+ console.log(headlines)
+ }).catch(error => console.log(error));
+```
+### Essence
+
+SECOND HALF (14.00 - 16.00)
+
+## 3. The `this` keyword and its relationship with `scope`
+
+### Explanation
+- The environment(or scope) in which the line is being executed is know as “Execution Context”
+- The object that `this` refers to, changes every time execution context is changed.
+- Whatever is calling the function passes the `this` value to it by default.
+- We can pass specific `this` by `.bind`, `.call` or `.apply`
+- By default, “this” refers to global object which is `global` in case of NodeJS and `window` object in case of browser
+
+### Example
+
+#### this refers to new instance (constructors)
+
+```javascript
+function logColor() {
+ // this inside the function refers to the calling javascript object
+ console.log('This refers to: ',this);
+ console.log('Color of this is: '+this.color);
+}
+let dog = { age: 5, color: 'brown', logColor: logColor};
+let car = { model: 'bmw', color: 'orange', logColor: logColor };
+
+console.log('log color called with dog')
+dog.logColor();
+console.log('log color called with car')
+car.logColor();
+```
+
+- In Javascript, property of an object can be a method or a simple value.
+- When an Object’s method is invoked then “this” refers to the object which contains the method being invoked.
+
+
+#### “this” refers to global object
+```javascript
+function logColor() {
+ // this inside the function refers to the calling javascript object
+ console.log('This refers to: ',this);
+ console.log('Color of this is: '+this.color);
+}
+
+console.log('log color called with no object')
+logColor(); // no calling object so "this" refers to window by default
+```
+> Note: the value of “this” depends on how a method is being invoked as well.
+
+#### “this” with call, apply methods
+- These methods can be used to set custom value of `this` to the execution context of function, also they can pass arguments/parameters to the function
+
+```javascript
+function logColor() {
+ // this inside the function refers to the calling javascript object
+ console.log('This refers to: ',this);
+ console.log('Color of this is: '+this.color);
+}
+let cat = { likes: 'milk', color: 'white'};
+logColor.call(cat); // calls the logColor function with cat as "this"
+```
+
+#### “this” with bind method
+`bind` only create a copy of the function with the binded `this` inside without calling the function.
+```
+function callAfterOneSecond(cb) {
+ setTimeout(function () {
+ cb();
+ }, 1000);
+}
+function logColor() {
+ // this inside the function refers to the calling javascript object
+ console.log('This refers to: ',this);
+ console.log('Color of this is: '+this.color);
+}
+let cat = { likes: 'milk', color: 'white'};
+let boundLogColor = logColor.bind(cat); // returns a function that can be executed later
+console.log(boundLogColor);
+// a few lines later
+boundLogColor(); // executes logColor with cat as "this"
+
+// callAfterOneSecond(boundLogColor);
+```
+
+
+> Note: If `strict mode` is enabled for any function then the value of “this” will be “undefined” as in strict mode, global object refers to undefined in place of windows object.
+
+```
+function foo() {
+ 'use strict';
+ console.log("Simple function call")
+ console.log(this === window);
+}
+
+foo(); //prints false on console as in “strict mode” value of “this” in global execution context is undefined.
+```
+
+#### “this” in arrow functions
+- The `this` value inside the arrow function gets binded and calculated and assigned based on its wrapper/container/parent `this` value.
+- The methods call(), apply(), and bind() will not change the value of this in arrow functions
+
+Students will learn mroe about this when learning about classes in javascript.
+
+
+### Excercise
+In this excercise, let the students guess the result and then go line by line as if you were an interpreter and execute the code. Or use the debugger tools on devtools to execute line by line.
+
+
+```javascript
+let user = {
+ a: 2,
+ b: 3,
+ print: function () {
+ console.log(multiply(this.a, this.b));
+ }
+}
+user.a = 5;
+user.print();
+user.b = 10;
+function multiply(p, q) {
+ return p * q;
+}
+```
+
+Variant two (if students find variant one too easy)
+
+```javascript
+let user = {
+ a: 2,
+ b: 3,
+ print: function () {
+ multiply(this.a, this.b, function (total) {
+ console.log(total);
+ console.log(this.a * this.b);
+ })
+ }
+}
+user.a = 5;
+user.print()
+user.b = 10;
+function multiply(p, q, callback) {
+ callback(p * q);
+}
+```
+
+### Essence
+this is special keyword in javascript. this refers to different things depending on how a function is called.
+
+
+
diff --git a/Week2/MAKEME.md b/Week2/MAKEME.md
index 8212430f6..d4f082dee 100644
--- a/Week2/MAKEME.md
+++ b/Week2/MAKEME.md
@@ -15,7 +15,62 @@ Let's start this week off with some interactive exercises! Visit the following l
## **2. JavaScript exercises**
-**_No exercises this week_**
+> Inside of your `JavaScript3` fork and inside of the `Week2` folder, create a folder called `homework`. Inside of that folder, create a folder called `js-exercises`. For all the following exercises create a new `.js` file in that folder (3 files in total). Make sure the name of each file reflects its content: for example, the filename for exercise one could be `getName.js`.
+
+**Exercise 1: John who?**
+
+Take a look at the following function (and try it out in your console):
+
+```js
+const getAnonName = (firstName, callback) => {
+ setTimeout(() => {
+ if (!firstName)
+ return callback(new Error("You didn't pass in a first name!"));
+
+ const fullName = `${firstName} Doe`;
+
+ return callback(fullName);
+ }, 2000);
+};
+
+getAnonName('John', console.log);
+```
+
+Rewrite this function, but replace the callback syntax with the Promise syntax:
+
+- Have the `getAnonName` function return a `new Promise` that uses the `firstName` parameter
+- If the Promise `resolves`, pass the full name as an argument to resolve with
+- If the Promise `rejects`, pass an error as the argument to reject with: "You didn't pass in a first name!"
+
+**Exercise 2: Is it bigger than 10?**
+
+Write a function called `checkDoubleDigits` that:
+
+- Takes 1 argument: a number
+- Returns a `new Promise`
+- If the number is bigger than 10, resolve with the string: "The number is bigger than 10!"
+- If the number is smaller than 10, reject with the error: "Error! The number is smaller than 10..."
+
+**Exercise 3: Gotta catch 'em all**
+
+> Inside of your `homework` folder, create another folder called `pokemon-app`. There, create an `index.html` and `script.js` file
+
+Let's catch all original 151 Pokemon in our own little web application! Here's an example of what you'll be building for this exercise:
+
+
+
+In this exercise you're going to do several things:
+
+1. Create and append DOM elements using JavaScript only
+2. Fetch data twice from a public API [PokeAPI](https://pokeapi.co/)
+3. Display the results in the DOM.
+
+Here are the requirements:
+
+- Create 3 functions: `fetchData`, `addPokemonToDOM` and `main`
+- The `main` function executes the other functions and contains all the variables
+- In the `fetchData` function, make use of `fetch` and its Promise syntax in order to get the data from the public API
+- Execute the `main` function when the window has finished loading
## **3. Code along**
@@ -27,57 +82,38 @@ Enjoy!
## **4. PROJECT: Hack Your Repo II**
-The assignment this week is to enhance your application to look similar to the following:
-
-
-
-As you can see, it looks different from the one from last week. This week we'll be rewriting most of our code to now show information for a single repository and also list its contributors (instead of the details for all repositories). A user should be able to search for all repositories in the account and select the one they want more information on.
+> This week we'll continue building on our work from last week. Make sure to navigate to the `hackyourrepo-app` folder and start based on the code you wrote!
-### Week 2 Assignment
+This week we'll do a couple of things:
-The enhanced application should fulfill the following requirements:
+1. We'll remove our HTML elements and remake them using JavaScript only!
+2. We'll replace our placeholder data with real data from the GitHub API
+3. We'll display this data in a separate column of the user interface
-1. The list of repositories in the `select` element should be sorted (case-insensitive) on repository name.
-2. At start-up your application should display information about the first repository as displayed in the `select` element.
-3. When the user changes the selection, the information in the web page should be refreshed for the newly selected repository.
-4. You should be able to click on the repository name of the selected repository to open a new browser tab with the GitHub page for that repository.
-5. You should be able to click on a contributor to open a new browser tab with the GitHub page for that contributor.
-6. Your UI should be responsive. Try it with Chrome Developer Tools in the browser, using a mobile phone format and a tablet format, portrait and landscape.
-7. The `XMLHttpRequest` in the `fetchJSON` function should be replaced with `fetch`. Hint: Because `fetch` returns a promise out of the box there is no need create a Promise yourself with `new Promise(...)`.
+On the surface, it'll look exactly the same. But functionally, it'll based around JavaScript only!
-**Hints:**
+Here are the requirements:
-- The `index.html` file can be divided into several components:
+- Remove the HTML elements you created last week, and only keep the `
-
-
-
-
-
-
-
+
diff --git a/hackyourrepo-app/script.js b/hackyourrepo-app/script.js
new file mode 100755
index 000000000..a2206d1ed
--- /dev/null
+++ b/hackyourrepo-app/script.js
@@ -0,0 +1,5 @@
+"use strict";
+
+/*
+ Write here your JavaScript for HackYourRepo!
+*/
diff --git a/hackyourrepo-app/style.css b/hackyourrepo-app/style.css
new file mode 100755
index 000000000..5b3acae8a
--- /dev/null
+++ b/hackyourrepo-app/style.css
@@ -0,0 +1,3 @@
+/*
+ Write here your CSS rules for HackYourRepo!
+*/
diff --git a/hand-in-homework-guide.md b/hand-in-homework-guide.md
index e8629dff6..710ff3cf3 100644
--- a/hand-in-homework-guide.md
+++ b/hand-in-homework-guide.md
@@ -6,34 +6,32 @@ In this module you'll submit your homework only using GIT and GitHub.
## 1. GitHub homework guide
-Follow the walkthrough to learn how to submit your homework for each week:
+
+
+Watch the video (by clicking the image) or go through the following walk-through to learn how to submit your homework:
ONE TIME ONLY (START OF EVERY MODULE)
-1. Create a [fork](https://help.github.com/en/articles/fork-a-repo) of the original module repository. You do this by using the `fork` option on the top right
-2. Navigate to the URL of the cloned repository (it should be in your personal GitHub account, under "repositories")
+1. Create a [fork](https://help.github.com/en/articles/fork-a-repo) of the following repository: [HackYourHomework/JavaScript3](https://www.github.com/hackyourhomework/javascript3). You do this by using the `fork` option on the top right
+2. Navigate to the URL of the forked repository (it should be in your personal GitHub account, under "repositories", under the name `/JavaScript3`)
3. Clone the repository, using SSH, to your local machine. You can do this by typing in `git clone ` in the command line
4. On your local machine, navigate to the folder using the command line
-5. Make sure you've cloned it correctly by running `git status` from the command line.
+5. Make sure you've cloned it correctly by running `git status` and `git remote -v` from the command line
EVERY WEEK
1. Create a new branch for each week you have homework. For example, for the week 1 homework for JavaScript3 create a branch called `week-1-homework-YOUR_NAME`
-2. Inside the correct week folder, create another folder called `homework`. Make your homework files in there, while on the correct branch
-3. Once you're finished, add and commit everything. Make the commit message meaningful, for example `finished project for homework week1`
-4. Push the branch to your forked repository
-5. On the GitHub page of your forked repository, click on the `create pull request` button. Make sure the `base repository` is the original, on branch master
+2. Inside the week folder, create another folder called `homework`. Create your homework files in there, while on the correct branch
+3. Once you're finished, `add` and `commit` everything. Make the commit message meaningful, for example `finished project for homework week1`
+4. Push the branch to your forked repository (`/JavaScript3`)
+5. On the GitHub page of this repository, click on the `create pull request` button. Make sure the `base repository` is `HackYourHomework/JavaScript3`, on branch master
6. Give the pull request a title in the following format:
```markdown
Homework week 1
```
-7. Submit the pull request from your forked repository branch into the `master` branch of the original repository
+7. Submit the pull request from your forked repository branch into the `master` branch of the original repository (`HackYourHomework/JavaScript3`)
8. Do a little victory dance because you did it! Good job!
-For a visual walkthrough the steps please watch the following video one of our teachers, Unmesh Joshi, has made:
-
-- [GitHub Homework flow](https://www.youtube.com/watch?v=2qJPAVTiKPE)
-
If you have any questions or if something is not entirely clear ¯\\\_(ツ)\_/¯, please ask/comment on Slack!
diff --git a/homework-classes/App.js b/homework-classes/App.js
deleted file mode 100755
index 8788f8b85..000000000
--- a/homework-classes/App.js
+++ /dev/null
@@ -1,56 +0,0 @@
-'use strict';
-
-{
- const accounts = {
- hyf: {
- name: 'HackYourFuture',
- type: 'org',
- },
- microsoft: {
- name: 'Microsoft',
- type: 'org',
- },
- jim: {
- name: 'remarcmij',
- type: 'user',
- },
- };
-
- const { Model, HeaderView, RepoView, ContributorsView, ErrorView } = window;
- const { createAndAppend } = window.Util;
-
- class App {
- constructor(account) {
- const containers = App.renderContainers();
-
- const model = new Model(account);
- const fetchData = model.fetchData.bind(model);
-
- model.subscribe(new HeaderView(account, containers.header, fetchData));
- model.subscribe(new RepoView(containers.repo));
- model.subscribe(new ContributorsView(containers.contributors));
- model.subscribe(new ErrorView(containers.error));
-
- fetchData();
- }
-
- static renderContainers() {
- const root = document.getElementById('root');
- const header = createAndAppend('header', root, { class: 'header' });
- const error = createAndAppend('div', root);
- const main = createAndAppend('main', root, {
- class: 'main-container',
- });
- const repo = createAndAppend('section', main, {
- class: 'repo-container whiteframe',
- });
- const contributors = createAndAppend('section', main, {
- class: 'contributors-container whiteframe',
- });
- return { header, error, main, repo, contributors };
- }
- }
-
- const ACCOUNT_KEY = 'hyf';
- window.onload = () => new App(accounts[ACCOUNT_KEY]);
-}
diff --git a/homework-classes/ContributorsView.js b/homework-classes/ContributorsView.js
deleted file mode 100755
index 58cb2b984..000000000
--- a/homework-classes/ContributorsView.js
+++ /dev/null
@@ -1,28 +0,0 @@
-'use strict';
-
-{
- const { createAndAppend } = window.Util;
-
- class ContributorsView {
- constructor(container) {
- this.container = container;
- }
-
- update(state) {
- if (!state.error) {
- this.render(state.contributors);
- }
- }
-
- /**
- * Renders the list of contributors
- * @param {Object[]} contributors An array of contributor objects
- */
- render(contributors) {
- // TODO: replace this comment and the console.log with your own code
- console.log('ContributorsView', contributors);
- }
- }
-
- window.ContributorsView = ContributorsView;
-}
diff --git a/homework-classes/ErrorView.js b/homework-classes/ErrorView.js
deleted file mode 100755
index 67ad53087..000000000
--- a/homework-classes/ErrorView.js
+++ /dev/null
@@ -1,31 +0,0 @@
-'use strict';
-
-{
- const { createAndAppend } = window.Util;
-
- class ErrorView {
- constructor(container) {
- this.container = container;
- }
-
- update(state) {
- this.render(state.error);
- }
-
- /**
- * Renders an error for the 'error' message type.
- * @param {Error} error An Error object
- */
- render(error) {
- this.container.innerHTML = '';
- if (error) {
- createAndAppend('div', this.container, {
- text: error.message,
- class: 'alert alert-error',
- });
- }
- }
- }
-
- window.ErrorView = ErrorView;
-}
diff --git a/homework-classes/HeaderView.js b/homework-classes/HeaderView.js
deleted file mode 100755
index 11f9c8971..000000000
--- a/homework-classes/HeaderView.js
+++ /dev/null
@@ -1,46 +0,0 @@
-'use strict';
-
-{
- const { createAndAppend } = window.Util;
-
- class HeaderView {
- constructor(account, header, fetchData) {
- this.account = account;
- this.header = header;
- this.fetchData = fetchData;
- this.select = null;
- }
-
- update(state) {
- if (!this.select && !state.error) {
- this.render(state.repos);
- }
- }
-
- /**
- * Renders the data for the 'select' message type. Create a element
- * and its children.
- * @param {Object[]} repos An array of repository objects.
- */
- render(repos) {
- createAndAppend('div', this.header, { text: this.account.name });
- this.select = createAndAppend('select', this.header, {
- class: 'repo-select',
- autofocus: 'autofocus',
- });
-
- repos.forEach(repo =>
- createAndAppend('option', this.select, {
- text: repo.name,
- value: repo.id,
- }),
- );
-
- this.select.addEventListener('change', () =>
- this.fetchData(this.select.value),
- );
- }
- }
-
- window.HeaderView = HeaderView;
-}
diff --git a/homework-classes/Model.js b/homework-classes/Model.js
deleted file mode 100755
index 25884a133..000000000
--- a/homework-classes/Model.js
+++ /dev/null
@@ -1,53 +0,0 @@
-'use strict';
-
-{
- const { Observable } = window;
-
- const makeUrl = ({ name, type }) =>
- `https://api.github.com/${type}s/${name}/repos?per_page=100`;
-
- class Model extends Observable {
- constructor(account) {
- super();
- this.account = account;
- this.state = {
- repos: [],
- selectedRepo: null,
- contributors: [],
- error: null,
- };
- }
-
- async fetchData(id) {
- const repoId = parseInt(id, 10);
- this.state.error = null;
- try {
- if (this.state.repos.length === 0) {
- const repos = await Model.fetchJSON(makeUrl(this.account));
- this.state.repos = repos.sort((a, b) => a.name.localeCompare(b.name));
- }
- const index = id
- ? this.state.repos.findIndex(repo => repo.id === repoId)
- : 0;
- this.state.selectedRepo = this.state.repos[index];
- this.state.contributors = await Model.fetchJSON(
- this.state.selectedRepo.contributors_url,
- );
- } catch (err) {
- this.state.error = err;
- }
- this.notify(this.state);
- }
-
- static fetchJSON(url) {
- return fetch(url).then(res => {
- if (!res.ok) {
- return new Error(`HTTP ${res.status} - ${res.statusText}`);
- }
- return res.status === 200 ? res.json() : null;
- });
- }
- }
-
- window.Model = Model;
-}
diff --git a/homework-classes/Observable.js b/homework-classes/Observable.js
deleted file mode 100755
index 3eb5b2530..000000000
--- a/homework-classes/Observable.js
+++ /dev/null
@@ -1,20 +0,0 @@
-'use strict';
-
-{
- class Observable {
- constructor() {
- this.observers = new Set();
- }
-
- subscribe(observer = {}) {
- this.observers.add(observer);
- return () => this.observers.delete(observer);
- }
-
- notify(data) {
- this.observers.forEach(observer => observer.update(data));
- }
- }
-
- window.Observable = Observable;
-}
diff --git a/homework-classes/RepoView.js b/homework-classes/RepoView.js
deleted file mode 100755
index 073166fea..000000000
--- a/homework-classes/RepoView.js
+++ /dev/null
@@ -1,28 +0,0 @@
-'use strict';
-
-{
- const { createAndAppend } = window.Util;
-
- class RepoView {
- constructor(container) {
- this.container = container;
- }
-
- update(state) {
- if (!state.error) {
- this.render(state.selectedRepo);
- }
- }
-
- /**
- * Renders the repository details.
- * @param {Object} repo A repository object.
- */
- render(repo) {
- // TODO: replace this comment and the console.log with your own code
- console.log('RepoView', repo);
- }
- }
-
- window.RepoView = RepoView;
-}
diff --git a/homework-classes/Util.js b/homework-classes/Util.js
deleted file mode 100755
index dc5d79a87..000000000
--- a/homework-classes/Util.js
+++ /dev/null
@@ -1,27 +0,0 @@
-'use strict';
-
-{
- class Util {
- /**
- * Creates an element, optionally setting its attributes, and appends
- * the element to a parent.
- * @param {string} name The tag name of the element to create.
- * @param {HTMLElement} parent The parent element.
- * @param {Object} options An object with attribute names and values.
- */
- static createAndAppend(name, parent, options = {}) {
- const elem = document.createElement(name);
- parent.appendChild(elem);
- Object.entries(options).forEach(([key, value]) => {
- if (key === 'text') {
- elem.textContent = value;
- } else {
- elem.setAttribute(key, value);
- }
- });
- return elem;
- }
- }
-
- window.Util = Util;
-}
diff --git a/homework-classes/style.css b/homework-classes/style.css
deleted file mode 100755
index 90d106051..000000000
--- a/homework-classes/style.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.alert-error {
- color: red;
-}
diff --git a/homework/hyf.png b/homework/hyf.png
deleted file mode 100755
index 76bc5a13b..000000000
Binary files a/homework/hyf.png and /dev/null differ
diff --git a/homework/index.html b/homework/index.html
deleted file mode 100755
index 9c8f80c1a..000000000
--- a/homework/index.html
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- Codestin Search App
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/homework/index.js b/homework/index.js
deleted file mode 100755
index 3886cbac9..000000000
--- a/homework/index.js
+++ /dev/null
@@ -1,54 +0,0 @@
-'use strict';
-
-{
- function fetchJSON(url, cb) {
- const xhr = new XMLHttpRequest();
- xhr.open('GET', url);
- xhr.responseType = 'json';
- xhr.onload = () => {
- if (xhr.status >= 200 && xhr.status <= 299) {
- cb(null, xhr.response);
- } else {
- cb(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`));
- }
- };
- xhr.onerror = () => cb(new Error('Network request failed'));
- xhr.send();
- }
-
- function createAndAppend(name, parent, options = {}) {
- const elem = document.createElement(name);
- parent.appendChild(elem);
- Object.entries(options).forEach(([key, value]) => {
- if (key === 'text') {
- elem.textContent = value;
- } else {
- elem.setAttribute(key, value);
- }
- });
- return elem;
- }
-
- function renderRepoDetails(repo, ul) {
- createAndAppend('li', ul, { text: repo.name });
- }
-
- function main(url) {
- fetchJSON(url, (err, repos) => {
- const root = document.getElementById('root');
- if (err) {
- createAndAppend('div', root, {
- text: err.message,
- class: 'alert-error',
- });
- return;
- }
- const ul = createAndAppend('ul', root);
- repos.forEach(repo => renderRepoDetails(repo, ul));
- });
- }
-
- const HYF_REPOS_URL =
- 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
- window.onload = () => main(HYF_REPOS_URL);
-}
diff --git a/homework/style.css b/homework/style.css
deleted file mode 100755
index 90d106051..000000000
--- a/homework/style.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.alert-error {
- color: red;
-}
diff --git a/package-lock.json b/package-lock.json
index 7ccbb2e22..0d74aedda 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1016,9 +1016,9 @@
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
},
"prettier": {
- "version": "1.18.2",
- "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz",
- "integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw=="
+ "version": "1.19.1",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
+ "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew=="
},
"prettier-linter-helpers": {
"version": "1.0.0",
diff --git a/package.json b/package.json
index a3233dcca..685329c36 100755
--- a/package.json
+++ b/package.json
@@ -15,6 +15,6 @@
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.0",
- "prettier": "^1.18.2"
+ "prettier": "^1.19.1"
}
}
diff --git a/test.md b/test.md
index 448f045f7..168ba207d 100644
--- a/test.md
+++ b/test.md
@@ -1,11 +1,25 @@
-# Final JavaScript Test
+# Final javascript test
-It will be about all the JavaScript you’ve learned, from JavaScript1 to JavaScript3.
+You’ll be doing a final JavaScript test. It will be about all the JavaScript you’ve learned, from JavaScript 1 to JavaScript 3.
+
+## Practical information
+
+- The test will last **2 hours**.
+- It will be done on the computer.
+- You can’t use your old code.
+- There will be 6 or 7 questions.
## Purpose of the test
-We want to make sure you understand and master the material well enough to confidently go on in the program. We also want to see if you can keep up with the pace.
-Test material
+The purpose of this exam is to test your comprehension of JavaScript
+
+- The goal for us is to know how solid your knowledge is and if you need any extra assistance throughout the program.
+- The goal for you is to test how well enough you master the material so far.
+
+Like the homework you will get feedback and are expected to improve upon your weak points.
+
+## Test material
+
The test will be about all main JavaScript concepts we have discussed for the past weeks of JS. The following are the most important that will be tested:
- `Functions & Variables`
@@ -15,21 +29,38 @@ The test will be about all main JavaScript concepts we have discussed for the pa
- `Array functions`
- `Conditional statements`
- `DOM manipulations`
-- `XMLHttpRequests & API calls`
+- `Fetch & HTTP Requests`
+- `Promises & Async/await`
- `Try…catch`
-## How to prepare optimally
+## Preparation
+
+Advice on how to optimally prepare:
+
+- Find out 2 things about each concepts listed above: (1) how does the basic structure look and (2) what is the most common use case.
+- Ask questions through Slack to your teachers and/or your classmates.
+- Practice for understanding (why something is the case), NOT just for repetition shake (and hoping ‘you will understand it one day’).
+- Make a summary of all the study material.
+- After you prepared try to make the sample questions that are in this file.
-For each of these you must be able to (1) write the basic code structure of it, (2) know when to apply them, and (3) apply it coherently with the rest of your code.
+## During the test
-## What type of questions to expect
+Advise on how to make a test:
-You are expected to solve several coding challenges. These include DOM manipulation and making API Calls.
+- **Look for low hanging fruit**. Which of the assignments is easiest for you to do? Tackle that one first.
+- **When writing your code, write small chunks at a time, testing each time before continuing**. Use temporary console.log statements to show intermediate results (remove when no longer needed). Don't continue until the code written sofar is working correctly. If you write a whole bunch of code without intermediate testing it becomes difficult to pinpoint where issues occur.
+- **If you get stuck in an assignment, move on** to the next one. You can always come back later if time permits.
+- When writing code for the browser, **always open the Chrome Developer Tools**. Watch out for error messages in the browser console. Inspect the network tab to examine the data returned from a remote API.
+- **Don't over-deliver**. If styling is not required by the assignment, skip it. If time permits, you can do it later. The same goes for handling fetch errors. Focus on delivering a minimum working version that meets the requirement. Ticking off a working version again reduces your stress level. Come back later, if time permits, to embellish your solutions.
+- **Don't use Google as a replacement for common sense.**
+- After finishing an assignment, read the question again to **make sure you actually gave an answer to the question.**
+- Before handing in the test, read it all over again to **pick out the small mistakes.**
-## What tools to use
+## Sample questions
-This test will be done on your laptop. You may use Google to help you out, but not the code from your homeworks.
+1. Using JavaScript only (adding HTML to index.html is NOT allowed), create a button element (with text "click me!") and an empty image element and add it to the document. When the button is clicked, insert an image URL into the tag and remove the button. Use the following image URL: https://thehub.dk/files/5ad4b4a9f9ac4aa13c3d2d58/logo_upload-6d537cf7e5de664db275b32b3c6ae12d.png
-## Time and location
+2. Make a HTTP Request using the Fetch API or the regular XMLHttpRequest (whichever one you're more comfortable with). Use the following API: https://reqres.in/api/users
+ Parse the response and then display the "first_name" and "last_name" of the first three users within the DOM (inside an unordered list)
-The test will be held in the usual place, will start at 11.00 and takes about an hour to complete. Doors will open at 10:45 the latest so please be in time.
+If there’s anything unclear please let us know. Also, if any of you need additional support, now is the moment to let us know as we could pair you up with someone to answer any questions you may have.