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

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e968a79

Browse files
authored
Merge pull request #339 from HackYourFuture/prep-class23
Prep class23
2 parents 7c3bc54 + 2d0dd25 commit e968a79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2130
-997
lines changed

.eslintrc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": ["airbnb", "prettier"],
2+
"extends": ["airbnb-base", "prettier"],
33
"plugins": ["prettier"],
44
"env": {
55
"browser": true,
@@ -9,14 +9,16 @@
99
"page": true,
1010
"browser": true,
1111
"context": true,
12-
"jestPuppeteer": true
12+
"jestPuppeteer": true,
13+
"axios": "readonly"
1314
},
1415
"rules": {
1516
"prettier/prettier": ["error"],
1617
"class-methods-use-this": "off",
1718
"strict": "off",
1819
"no-plusplus": "off",
1920
"linebreak-style": "off",
21+
"no-restricted-syntax": "off",
2022
"no-param-reassign": [
2123
"error",
2224
{

.vscode/extensions.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"recommendations": [
3+
"CoenraadS.bracket-pair-colorizer",
4+
"dbaeumer.vscode-eslint",
5+
"esbenp.prettier-vscode",
6+
"ritwickdey.LiveServer",
7+
"streetsidesoftware.code-spell-checker",
8+
"techer.open-in-browser"
9+
]
10+
}

.vscode/settings.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
"editor.detectIndentation": false,
66
"editor.tabSize": 2,
77
"cSpell.words": [
8+
"READYSTATE",
9+
"Traversy",
10+
"ajaxcrash",
811
"networkidle",
9-
"tabindex"
12+
"remarcmij",
13+
"tabindex",
14+
"whiteframe"
1015
]
11-
}
16+
}

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ or links, please share them by [opening a pull request](https://github.com/HackY
33

44
# HackYourFuture JavaScript 3
55

6-
Here you can find course content and homework for the JavaScript3 modules
6+
Here you can find course content and homework for the JavaScript3 modules.
77

88
|Week|Topic|Read|Homework|
99
|----|-----|----|--------|
10-
|1.|• Structure for a basic SPA (Single Page Application) <br>• [XMLHttpRequests](../../../fundamentals/blob/master/fundamentals/XMLHttpRequest.md) <br>• API calls|[Reading Week 1](/Week1/README.md)|[Homework Week 1](/Week1/MAKEME.md)|
11-
|2.|[Event Loop (order of execution)](../../../fundamentals/blob/master/fundamentals/event_loop.md)<br>• [Promises](../../../fundamentals/blob/master/fundamentals/promises.md)|[Reading Week 2](/Week2/README.md)|[Homework Week 2](/Week2/MAKEME.md)|
12-
|3.|[try...catch](../../../fundamentals/blob/master/fundamentals/try_catch.md)<br>• [async/await](../../../fundamentals/blob/master/fundamentals/async_await.md)<br>• [The `this` keyword](../../../fundamentals/blob/master/fundamentals/this.md)<br>• call, apply, bind<br>• [Object Oriented Programming and ES6 Classes](../../../fundamentals/blob/master/fundamentals/oop_classes.md)|[Reading Week 3](/Week3/README.md)|[Homework Week 3](/Week3/MAKEME.md)|
10+
|1.|• Structure for a basic SPA (Single Page Application) <br>• AJAX & XMLHttpRequests<br>• API calls|[Reading Week 1](/Week1/README.md)|[Homework Week 1](/Week1/MAKEME.md)|
11+
|2.|• Event Loop (order of execution)<br>• Promises|[Reading Week 2](/Week2/README.md)|[Homework Week 2](/Week2/MAKEME.md)|
12+
|3.|fetch, axios<br>• async/await<br>• try...catch<br>• The `this` keyword<br>• call, apply, bind<br>• Object Oriented Programming and ES6 Classes|[Reading Week 3](/Week3/README.md)|[Homework Week 3](/Week3/MAKEME.md)|
1313

1414
__Kind note:__
1515

@@ -18,6 +18,6 @@ We expect you to __always__ come prepared to the class on Sunday.
1818
### Overall
1919
A good understanding of all the above mentioned topics. Want to check your Knowledge? Go through the [JavaScript Fundamentals README](../../../fundamentals/blob/master/README.md) and research/ ask for help (Slack!) with the concepts that are not entirely clear.
2020

21-
*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 :)*
21+
*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* :).
2222

2323
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.

Week1/MAKEME.md

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ _This homework is more extensive and challenging than previous homework! Please
1919
2020
You are going to write a _Single Page Application_ (SPA) that uses the [GitHub API](https://developer.github.com/guides/getting-started/).
2121

22-
This application should display information about the available [HYF GitHub repositories](https://github.com/hackyourfuture). The functionalities we would like to see in your application are as follows:
22+
This application should display information about the available [HYF GitHub repositories](https://github.com/hackyourfuture). The functionalities we would like to see in your application in the first week are as follows:
2323

24-
- The user should be able to select a repository from a list of available repositories.
25-
- The application should display high-level information about the selected repository and show a list of its contributors.
26-
- When clicking on the name of the selected repository the GitHub page for the corresponding repository should be opened in a new browser tab.
27-
- When clicking on a contributor, the GitHub page for the contributor should be opened in a new browser tab.
24+
- The application should fetch repository information for the HYF GitHub account and display summary information for each repository.
25+
- This list of repositories should be sorted alphabetically by repository name.
2826

29-
Figure 1 below shows an example of what your application could look like. Note that this is just an example. If you find it boring or unimaginative, please improve on it! On the other hand, a simpler version is OK too, so long as you implement the expected functionality.
27+
Figure 1 below shows an example of what your application could look like.
3028

3129
![UI Example](./assets/hyf-github.png)
3230

@@ -48,11 +46,7 @@ If you open this URL in the browser (_try it!_) you will receive JSON data about
4846

4947
The returned JSON data contains some basic information about each repository, such as `name`, `full_name`, `description` etc. There are also many properties that contain URLs that can be used to obtain detail information about certain aspects of the repository.
5048

51-
#### 1.2.2 Get contributor information for a repository
52-
53-
The JSON data that is returned from the initial request to get repository information includes a property named `contributors_url`. Use the value of this property to fetch a list of contributors.
54-
55-
#### 1.2.3 GitHub API documentation
49+
#### 1.2.2 GitHub API documentation
5650

5751
You can find detailed information about the GitHub API by means of the link listed below. However, the documentation is very extensive and not easy to digest. For this homework it is not necessary to study the GitHub API documentation. We provide the link here for completeness.
5852

@@ -70,11 +64,11 @@ While you do not need to read this guide in detail, it is recommended that you r
7064

7165
You will be working on the same application during the next three weeks. For each week you will need to create a new Git branch, as listed in the Table 1 below.
7266

73-
| Week | Branch | Assignment |
74-
| :--: | ------- | -------------------------------------------------------------------------------------------------------------------------------- |
75-
| 1 | `week1` | - Create a basic application using callbacks to handle network requests. |
76-
| 2 | `week2` | Based on the `week1` branch:<br>- Refactor the callbacks to promises.<br>- Make the UI responsive. |
77-
| 3 | `week3` | Based on the `week2` branch:<br>- Refactor the application to use ES6 Classes and async/await.<br>- Make the app ARIA-compliant. |
67+
| Week | Branch | Assignment |
68+
| :--: | ------- | ---------- |
69+
| 1 | `week1` | - Create a basic application using callbacks to handle network requests. |
70+
| 2 | `week2` | Based on the `week1` branch:<br>- Display details on a single repository and its contributors<br>- Refactor the callbacks to promises. |
71+
| 3 | `week3` | Based on the `week2` branch:<br>- Refactor the application to use `fetch` and `async`/`await`.<br>- Reuse portions of the code to complete a provided Object Oriented (OOP) version of the application that uses ES6 classes. |
7872

7973
<small>Table 1. Homework schedule</small>
8074

@@ -83,17 +77,13 @@ You will be working on the same application during the next three weeks. For eac
8377
1. Fork the JavaScript3 repository (_this repository_) to your own GitHub account.
8478
2. Clone the fork to your laptop.
8579
3. Open the newly created `JavaScript3` folder from the cloned repository in VSCode.
86-
4. Install the following extension in VSCode:
87-
88-
**Prettier - Code formatter**.
89-
90-
5. Open a Terminal window in VSCode and type the following command to install Prettier and ESLint tools as required for the homework:
80+
4. Open a Terminal window in VSCode and type the following command to install Prettier and ESLint tools as required for the homework:
9181

9282
```
9383
npm install
9484
```
9585

96-
6. Create a new branch for the week 1 homework with the following command:
86+
5. Create a new branch for the week 1 homework with the following command:
9787

9888
```
9989
git checkout -b week1
@@ -135,37 +125,23 @@ _**Do not change or delete any files outside of the `homework` folder!**_
135125
| `createAndAppend` | A utility function for easily creating and appending HTML elements. |
136126
| `main` | Contains the start-up code for the application. |
137127

138-
`index.js` also contains a constant with the URL for the HYF repositories as listed in section 2.2.1:
128+
`index.js` also contains a constant with the URL required for fetching information about the HYF repositories:
139129

140130
```js
141131
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
142132
```
143133

144-
3. Open the `index.html` file in your browser. Notice that it produces the same JSON output that you saw previously when you opened the URL directly in the browser.
134+
3. Open the `index.html` file in your browser. You will see an unordered list with the names of the HYF repositories.
145135

146-
4. Review the `main()` function in `index.js` and examine how this code renders the JSON output in the browser by means of a `pre` HTML element (for demonstration purposes).
136+
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.
147137

148138
### 1.6 Week 1 Assignment
149139

150-
The assignment is to produce an application similar to the one illustrated in Figure 1 above.
151-
152-
It should include the following components:
153-
154-
1. An HTML `select` element from which the user can select a HYF repository. This `select` element must be populated with `option` elements, one for each HYF repository.
155-
2. A left-hand column that displays basic information about the selected repository.
156-
3. A right-hand column that displays a list of contributors to the repository.
140+
1. The assignment is to produce an application similar to the one illustrated in Figure 1 above.
157141

158-
> In case you run out of time, you can also do the contributors list in week 2.
142+
2. You should 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. Use the predefined `alert-error` class from `style.css` to style your error.
159143

160-
**Functional Requirements:**
161-
162-
1. The list of repositories in the `select` element should be sorted (case-insensitive) on repository name.
163-
2. At start-up your application should display information about the first repository as displayed in the `select` element.
164-
3. When the user changes the selection, the information in the web page should be refreshed for the newly selected repository.
165-
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.
166-
5. You should be able to click on a contributor to open a new browser tab with the GitHub page for that contributor.
167-
6. You should 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. Use the predefined `alert-error` class from `style.css` to style your error.
168-
7. 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. If necessary, you can also do this work in week 2.
144+
3. 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. If necessary, you can also do this work in week 2.
169145

170146
![Error rendering](./assets/hyf-github-error.png)
171147

@@ -179,31 +155,24 @@ It should include the following components:
179155

180156
**`style.css`**
181157

182-
- Add your own styling.
183-
184-
**Hints:**
158+
- Add your own CSS styling. Use `style.css` for all your styling your HTML. Avoid using JavaScript for styling unless there is a genuine need.
185159

186-
- Add one `option` element per repository to the `select` element, where each `option` element has the array index of the repository as its `value` attribute and the name of the repository as its text content:
160+
**You are not allowed to use a CSS library such as Bootstrap.**
187161

188-
```html
189-
<select>
190-
<option value="0">alumni</option>
191-
<option value="1">angular</option>
192-
<!-- etc -->
193-
</select>
194-
```
162+
**Hints:**
195163

196164
* 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).
197165

198166
* Use CSS media queries and [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) to make the UI responsive.
199167

200168
* 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`.
201169

170+
202171
### 1.7 Handing in your homework
203172

204173
If necessary, review the instructions how to [Hand in homework](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/homework_pr.md) using GitHub pull request.
205174

206-
To test whether your code will be accepted when you submit your homework as a pull request you need to ensure that it does not contain ESLinr errors. Open a terminal window in VSCode and type the following command:
175+
To test whether your code will be accepted when you submit your homework as a pull request you need to ensure that it does not contain ESLint errors. Open a terminal window in VSCode and type the following command:
207176

208177
```
209178
npm test

Week1/README.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,73 @@
33
```
44
In week one we will discuss the following topics:
55
• Structure for a basic SPA (Single Page Application)
6-
• XMLHttpRequests
6+
AJAX & XMLHttpRequests
77
• API calls
88
```
99

1010
Here are resources that we like you to read as a preparation for the first lecture:
1111

12-
### Fundamentals
12+
## 1. DOM manipulation
1313

14-
- [XMLHttpRequest](../../../../fundamentals/blob/master/fundamentals/XMLHttpRequest.md)
14+
To refresh your DOM manipulation skills, watch this YouTube video series from Traversy Media:
1515

16-
### APIs
16+
- [JavaScript DOM Crash Course](https://youtu.be/0ik6X4DJKCc).
1717

18-
- Read about APIS: https://www.programmableweb.com/api-university/what-are-apis-and-how-do-they-work
18+
You will be using these particular DOM manipulation methods and properties in the JS3 homework for the next three weeks:
1919

20-
### XMLHttpRequests
20+
#### Course Video Part 1 (39 mins):
21+
22+
- `document.getElementById()`
23+
- `element.textContent`
24+
25+
#### Course Video Part 2 (21 mins):
26+
27+
- `document.createElement()`
28+
- `element.setAttribute()`
29+
- `element.appendChild()`
30+
31+
#### Course Video Part 3 (34 mins):
32+
33+
- `change` event (`<select>` element)
34+
- `element.addEventListener()`
35+
36+
Note that throughout the video lectures the presenter uses `var` to declare variables. We prefer that you use `const` and `let` instead in your homework.
37+
38+
## 2. APIs
39+
40+
In the homework we will be using the GitHub API. Learn about remote Web APIs in general from this YouTube video (18 min) from Traversy Media:
41+
42+
- [What Is A RESTful API? Explanation of REST & HTTP](https://youtu.be/Q-BpqyOT3a8).
43+
44+
For more research, check out the following resources:
45+
46+
- [What are APIs - series](https://www.youtube.com/watch?v=cpRcK4GS068&list=PLcgRuP1JhcBP8Kh0MC53GH_pxqfOhTVLa)
47+
48+
## 3. AJAX & XMLHttpRequests
49+
50+
Please watch the first 45 mins of the Ajax Crash Course (up until the PHP examples) by Traversy Media:
51+
52+
- [Ajax Crash Course](https://youtu.be/82hnvUYY6QA)
53+
54+
The example code in this course is using on ES5 syntax. In the **traversy_ajax_crash** folder in this repo you will find updated example code (**ajax1**...**ajax3**) that use the ES6 syntax and styling that we prefer in HYF. Specifically, the following changes have been made:
55+
56+
1. The JavaScript code has been placed in a separate file, loaded with a `<script>` tag from the HTML file.
57+
2. Instead of **var** to declare a variable, **const** and **let** are used.
58+
3. The non-strict equality operator `==` has been replaced with the strict version `===`.
59+
4. Functions are defined before they are used.
60+
5. Anonymous functions use the arrow syntax instead of the **function** keyword. Consequently, the `this` value inside the **XMLHttpRequest** event handlers have been replaced with the `xhr` variable name.
61+
6. The `for...in` loops for iterating through an array have been replace with `for...of`.
62+
63+
Read more about using **XMLHttpRequest**:
2164

2265
- [Making HTTP Requests in JavaScript](https://www.kirupa.com/html5/making_http_requests_js.htm)
2366

2467
### Clean Code
2568

26-
- [How to write clean code? Lessons learnt from “The Clean Code” — Robert C. Martin](https://medium.com/mindorks/how-to-write-clean-code-lessons-learnt-from-the-clean-code-robert-c-martin-9ffc7aef870c).
27-
28-
> Note that this article includes some code examples writte in Java, but the same principles can equally be applied to JavaScript.
69+
- [How to write clean code? Lessons learnt from “The Clean Code” — Robert C. Martin](https://medium.com/mindorks/how-to-write-clean-code-lessons-learnt-from-the-clean-code-robert-c-martin-9ffc7aef870c). Note that this article includes some code examples written in Java, but the same principles can equally be applied to JavaScript.
2970

3071
- [Clean Code concepts adapted for JavaScript](https://github.com/ryanmcdermott/clean-code-javascript)
3172

3273
### Handing in homework using GitHub pull requests
3374

34-
- [Handing in homework](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/homework_pr.md)
75+
- HYF Fundamental - [Handing in homework](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/homework_pr.md)

Week1/assets/hyf-github-error.png

0 Bytes
Loading

Week1/assets/hyf-github.png

0 Bytes
Loading

Week1/traversy_ajax_crash/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# AJAX Crash Course
2+
3+
Please watch the first 45 mins of the Ajax Crash Course by Traversy Media (see link below).
4+
5+
The example code in this course is using on ES5 syntax. In the **ajaxcrash** folder in this repo you will find updated example code (**ajax1** to **ajax3**) that use the ES6 syntax and styling that we prefer in HYF. Specifically, the following changes have been made:
6+
7+
1. The JavaScript code has been placed in a separate file, loaded with a `<script>` tag from the HTML file.
8+
2. Instead of **var** to declare a variable, **const** and **let** are used.
9+
3. The non-strict equality operator `==` has been replaced with the strict version `===`.
10+
4. Functions are defined before they are used.
11+
5. Anonymous functions use the arrow syntax instead of the **function** keyword. Consequently, the `this` value inside the **XMLHttpRequest** event handlers have been replaced with the `xhr` variable name.
12+
6. The `for...in` loops for iterating through an array have been replace with `for...of`.
13+
14+
Watch this YouTube video up until the PHP examples (the first 45 mins):
15+
16+
- Traversy Media - [Ajax Crash Course](https://youtu.be/82hnvUYY6QA)

0 commit comments

Comments
 (0)