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

Skip to content

Commit 56ed1b8

Browse files
author
Noer Paanakker
committed
merged with master, finalized homeworks/readings
2 parents 150b899 + e968a79 commit 56ed1b8

Some content is hidden

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

61 files changed

+7507
-775
lines changed

.eslintrc.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
{
2-
"extends": ["airbnb", "prettier"],
2+
"extends": ["airbnb-base", "prettier"],
33
"plugins": ["prettier"],
44
"env": {
5-
"browser": true
5+
"browser": true,
6+
"jest": true
7+
},
8+
"globals": {
9+
"page": true,
10+
"browser": true,
11+
"context": true,
12+
"jestPuppeteer": true,
13+
"axios": "readonly"
614
},
715
"rules": {
816
"prettier/prettier": ["error"],
917
"class-methods-use-this": "off",
1018
"strict": "off",
1119
"no-plusplus": "off",
1220
"linebreak-style": "off",
21+
"no-restricted-syntax": "off",
1322
"no-param-reassign": [
1423
"error",
1524
{

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ typings/
5959

6060
.netlify
6161
dist/
62+
iPhoneX.png

.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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"editor.detectIndentation": false,
66
"editor.tabSize": 2,
77
"cSpell.words": [
8-
"tabindex"
8+
"READYSTATE",
9+
"Traversy",
10+
"ajaxcrash",
11+
"networkidle",
12+
"remarcmij",
13+
"tabindex",
14+
"whiteframe"
915
]
10-
}
16+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Welcome to JavaScript3! Congratulations on making it this far. You're well on yo
99

1010
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!
1111

12-
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 one such paradigm: Object-Oriented Programming!
12+
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!
1313

1414
## Learning goals
1515

Week1/MAKEME.md

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Who doesn't love kittens on their screen?
2424
Write an function that makes an API call to https://wwww.placekitten.com/api
2525

2626
- Inside the same file write two programs: one with `XMLHttpRequest`, and the other with `Axios`
27+
- Each function should make an API call to the given endpoint: `https://wwww.placekitten.com/api`
2728
- Log the received data to the console
2829
- Incorporate error handling
2930

@@ -33,7 +34,8 @@ Wouldn't it cool to make a new friend with just the click of a button?
3334

3435
Write a function that makes an API call to https://www.randomuser.me/api
3536

36-
- Inside the same file write two programs: one with `XMLHttpRequest`, and the other with `Axios`
37+
- Inside the same file write two functions: one with `XMLHttpRequest`, and the other with `Axios`
38+
- Each function should make an API call to the given endpoint: `https://www.randomuser.me/api`
3739
- Log the received data to the console
3840
- Incorporate error handling
3941

@@ -45,7 +47,8 @@ Write a function that makes an API call to https://picsum.photos/400
4547

4648
- Create an `index.html` file that will display your random image
4749
- Write two programs: one with `XMLHttpRequest`, and the other with `Axios`
48-
- After receiving the data, render it to the page in a `<li>`
50+
- Each function should make an API call to the given endpoint: `https://picsum.photos/400`
51+
- After receiving the data, render it to the page in a `<img>`
4952
- Incorporate error handling
5053

5154
## **3. Code along**
@@ -60,22 +63,20 @@ Enjoy!
6063

6164
## **4. PROJECT: Hack Your Repo I**
6265

63-
> In this assignment you will built upon some existing code that is already pre-written by your teachers. Your homework consist of writing the code to make the application work as requested per week.
64-
6566
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/).
6667

67-
Figure 1 below shows an example of what your application could look like.
68+
Figure 1 below shows an example of what your application will look like.
6869

6970
![UI Example](./assets/hyf-github.png)
7071

71-
This application serves 2 purpose:
72+
This application does 2 things:
7273

7374
1. It makes connection to the GitHub API and retrieves all the repositories found in the [HackYourFuture account](https://www.github.com/hackyourfuture).
7475
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.
7576

7677
### Getting an overview
7778

78-
For this week you're expected to build upon the pre-existing code, found in the folder `homework`. Here's what you'll find:
79+
For this week you're expected to build upon pre-existing code, found in the folder `homework`. Here's what you'll find:
7980

8081
| Filename | Description |
8182
| ------------ | --------------------------------- |
@@ -88,7 +89,7 @@ As you'll experience in your job, you'll be exposed to an already existing codeb
8889

8990
### A first examination
9091

91-
1. Open `index.html` and examine its contents (but don't modify anything). Notice that the HTML `body` looks like this:
92+
1. Open `index.html` and examine its contents (but don't modify anything). Notice that the HTML `<body>` looks like this:
9293

9394
```html
9495
<body>
@@ -97,7 +98,7 @@ As you'll experience in your job, you'll be exposed to an already existing codeb
9798
</body>
9899
```
99100

100-
The `body` tag contains a single `div` to which you will need to dynamically append HTML elements through your JavaScript code in `index.js`.
101+
The `<body>` tag contains a single `<div>` to which you will need to dynamically append HTML elements through your JavaScript code in `index.js`.
101102

102103
2. Open `index.js`. This file contains a starter set of code for you to expand. It contains the following three functions:
103104

@@ -107,7 +108,7 @@ As you'll experience in your job, you'll be exposed to an already existing codeb
107108
| `createAndAppend` | A utility function for easily creating and appending HTML elements. |
108109
| `main` | Contains the start-up code for the application. |
109110

110-
`index.js` also contains a constant with the URL required for fetching information about the HYF repositories:
111+
`index.js` also contains a variable with the URL required for fetching information about the HYF repositories:
111112

112113
```js
113114
const HYF_REPOS_URL =
@@ -124,25 +125,46 @@ As you'll experience in your job, you'll be exposed to an already existing codeb
124125
https://api.github.com/orgs/HackYourFuture/repos?per_page=100
125126
```
126127

127-
> This URL is special, as it gives us data in JSON format. 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/).
128+
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/).
129+
130+
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)).
131+
132+
## Week 1 Assignment:
133+
134+
The assignment for this week is to produce a functional application that looks similar to Figure 1:
135+
136+
![UI Example](./assets/hyf-github.png)
137+
138+
Functionally, the application should do the following:
139+
140+
1. Make an API call to the endpoint: https://api.github.com/orgs/HackYourFuture/repos?per_page=100
141+
2. Display the first 10 items in the HTML file (write JavaScript to add element to the DOM)
142+
3. Show feedback when an error has happened
143+
144+
Modify the following files:
145+
146+
**1. `index.js`**
147+
148+
- Add new functions and modify function `main()` as you see fit.
149+
- 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:
128150

129-
If you open this URL in the browser (_try it!_) you will receive JSON data about the available HYF repositories. This is the data that you will need to work with in this assignment.
151+
![Error rendering](./assets/hyf-github-error.png)
130152

131-
<small>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)).</small>
153+
<small>Figure 2. Rendering of network errors.</small>
132154

133-
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.
155+
**2. `style.css`**
134156

135-
### In Summary: the assignment
157+
- 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.
136158

137-
Do the following to fulfill this week's requirements:
159+
**You are not allowed to use a CSS library such as Bootstrap.**
138160

139-
1. Modify **`index.js`**: Modify whatever you need in order to successfully make an API call to the HackYourFuture GitHub account and display the results inside the DOM. It is not likely that you will need to modify `fetchJSON()` and `createAndAppend()`.
161+
**Hints:**
140162

141-
2. Add your own CSS styling inside **`style.css`**. Avoid using JavaScript for styling unless there is a genuine need. **You are not allowed to use a CSS library such as Bootstrap.**
163+
- 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).
142164

143-
**Hints**
165+
- Use CSS media queries, percentage values and [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) to make the UI responsive.
144166

145-
- Use CSS media queries and [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) to make the UI responsive.
167+
- 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`.
146168

147169
Good luck!
148170

@@ -153,7 +175,7 @@ After you've finished your todo list it's time to show us what you got! The home
153175
1. JavaScript exercises
154176
2. PROJECT: HackYourRepo I
155177

156-
Upload both to your forked JavaScript3 repository in GitHub. Make a pull request to the original repository.
178+
Upload both to your forked JavaScript3 repository in GitHub. Make a pull request to your teacher's forked repository.
157179

158180
> Forgotten how to upload your homework? Go through the [guide](../hand-in-homework-guide.md) to learn how to do this again.
159181

Week1/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ axios
171171

172172
Any library that exists is developed to solve some problem. The main problems `axios` aims to solve are the following:
173173

174-
1. how to much easier make an `HTTP request`
174+
1. how to make an `HTTP request` in an easier way
175175
2. how to write more readable asynchronous code.
176176

177177
Here's how `axios` solves problem 1:
@@ -180,13 +180,22 @@ Here's how `axios` solves problem 1:
180180

181181
Here's how `axios` solves problem 2:
182182

183-
-
183+
- It makes use of the Promise structure, which will allow you (the developer) to "chain" operations in a readable and intuitive way.
184184

185185
### How to use a library
186186

187-
Now that you've learned about the utility of libraries, let's talk a little about how to approach using a library. The first question we must ask is: when is it appropriate to use a library?
187+
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.
188188

189-
The second question is: how to start using a new library?
189+
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?
190+
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.
191+
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.
192+
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.
193+
194+
As an example, try it out with `axios`. To help you out, here are some resources:
195+
196+
- [Documentation](https://github.com/axios/axios)
197+
- [Guide - Written](https://blog.logrocket.com/how-to-make-http-requests-like-a-pro-with-axios/)
198+
- [Guide - Video](https://www.youtube.com/watch?v=oAHGpmyJD7g)
190199

191200
## Finished?
192201

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)

Week1/traversy_ajax_crash/ajax1.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Ajax 1 - Text File</title>
8+
</head>
9+
<body>
10+
<button id="button">Get Text File</button>
11+
<br /><br />
12+
<div id="text"></div>
13+
14+
<script src="ajax1.js"></script>
15+
</body>
16+
</html>

Week1/traversy_ajax_crash/ajax1.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-disable no-console */
2+
3+
'use strict';
4+
5+
{
6+
function loadText() {
7+
// Create XHR Object
8+
const xhr = new XMLHttpRequest();
9+
// OPEN - type, url/file, async
10+
xhr.open('GET', 'sample.txt', true);
11+
12+
console.log('READYSTATE: ', xhr.readyState);
13+
14+
// OPTIONAL - used for loaders
15+
xhr.onprogress = () => {
16+
console.log('READYSTATE: ', xhr.readyState);
17+
};
18+
19+
xhr.onload = () => {
20+
console.log('READYSTATE: ', xhr.readyState);
21+
if (xhr.status === 200) {
22+
// console.log(this.responseText);
23+
document.getElementById('text').innerHTML = xhr.responseText;
24+
} else if (this.status === 404) {
25+
document.getElementById('text').innerHTML = 'Not Found';
26+
}
27+
};
28+
29+
xhr.onerror = () => {
30+
console.log('Request Error...');
31+
};
32+
33+
// xhr.onreadystatechange = () => {
34+
// console.log('READYSTATE: ', xhr.readyState);
35+
// if xhr.readyState === 4 && xhr.status === 200){
36+
// //console.log(this.responseText);
37+
// }
38+
// }
39+
40+
// Sends request
41+
xhr.send();
42+
}
43+
44+
// readyState Values
45+
// 0: request not initialized
46+
// 1: server connection established
47+
// 2: request received
48+
// 3: processing request
49+
// 4: request finished and response is ready
50+
51+
// HTTP Statuses
52+
// 200: "OK"
53+
// 403: "Forbidden"
54+
// 404: "Not Found"
55+
56+
document.getElementById('button').addEventListener('click', loadText);
57+
}

Week1/traversy_ajax_crash/ajax2.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>Ajax 2 - Local JSON</title>
8+
</head>
9+
<body>
10+
<button id="button1">Get User</button>
11+
<button id="button2">Get Users</button>
12+
<br /><br />
13+
<h1>User</h1>
14+
<div id="user"></div>
15+
<h1>Users</h1>
16+
<div id="users"></div>
17+
18+
<script src="ajax2.js"></script>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)