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

Commit 5fada6f

Browse files
Gabe Rodriguezkvarak
authored andcommitted
Week 1 lecture notes and exercises
1 parent 907cd4a commit 5fada6f

File tree

5 files changed

+108
-7
lines changed

5 files changed

+108
-7
lines changed

README.md

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

66
Here you can find course content and homework for the JavaScript3 modules
77

8-
|Week|Topic|Read|Homework|
9-
|----|-----|----|--------|
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)|
8+
|Week|Topic|Read|Homework|Lecture notes|
9+
|----|-----|----|--------|-------------|
10+
|1.|• [XMLHttpRequests](../../../fundamentals/blob/master/fundamentals/XMLHttpRequest.md) <br />• API calls <br />• Structure for a basic SPA (Single Page Application) <br />|[Reading Week 1](/Week1/README.md)|[Homework Week 1](/Week1/MAKEME.md)|[notes](/Week1/LECTURENOTES.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)|[notes](/Week2/LECTURENOTES.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)|
1313

1414
__Kind note:__
1515

Week1/LECTURENOTES.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## XMLHttpRequests
2+
- What is an Http request?
3+
- Life of a request
4+
- https://dev.to/dangolant/things-i-brushed-up-on-this-week-the-http-request-lifecycle-
5+
- REST
6+
- Verbs
7+
- Headers
8+
- Status codes
9+
- Example w/ curl
10+
- Now how do we send a request with a browser?
11+
- Websites of the early era required a complete page load upon each request (https://en.wikipedia.org/wiki/Ajax_(programming))
12+
- This is inefficient and provides a bad user experience with full reloads on each action. Example: MapQuest in the early days.
13+
- AJAX
14+
- Gmail in 2004 and Google Maps in 2005
15+
- A way for browsers to send requests asyncronously! 🎉
16+
- In 2006, W3C releated XMLHttpRequest specification
17+
- XMLHttpRequest
18+
- Guide: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
19+
20+
## API calls
21+
- Open API's without need for auth tokens (https://github.com/public-apis/public-apis/blob/master/README.md). Use one for example.
22+
- Create new HTML file
23+
- Create a button that will have an event listener
24+
- Retrieve data from api with XMLHttpRequest obj
25+
26+
- ...but callbacks? [joke](https://www.reddit.com/r/ProgrammerHumor/comments/che938/asynchronous_javascript/)
27+
28+
29+
## Structure for a basic SPA

Week1/MAKEME.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
```
44
Topics discussed this week:
5-
• Structure for a basic SPA
65
• XMLHttpRequests
76
• API calls
7+
• Structure for a basic SPA
88
```
99

1010
## Step 1: Single Page Application :sweat_drops:

Week1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
```
44
In week one we will discuss the following topics:
5-
• Structure for a basic SPA (Single Page Application)
65
• XMLHttpRequests
76
• API calls
7+
• Structure for a basic SPA
88
```
99

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

Week1/search.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>TV show search</title>
5+
<style>
6+
#actors {
7+
display: flex;
8+
}
9+
</style>
10+
</head>
11+
<body>
12+
<input id="query" type="text" />
13+
<button id="search">Search Show</button>
14+
<div id="poster"></div>
15+
<div id="actors"></div>
16+
17+
<script>
18+
document.getElementById('search').addEventListener('click', () => {
19+
const inputText = document.getElementById('query').value;
20+
apiShowSearch(inputText);
21+
});
22+
23+
function apiShowSearch(searchQuery) {
24+
const xmlReq = new XMLHttpRequest();
25+
26+
xmlReq.addEventListener('load', event => {
27+
const response = JSON.parse(event.currentTarget.response);
28+
displayShowPoster(response);
29+
getActors(response[0].show.id);
30+
});
31+
32+
xmlReq.open('GET', `http://api.tvmaze.com/search/shows?q=${searchQuery}`, true);
33+
xmlReq.send();
34+
}
35+
36+
function displayShowPoster(showResultsArr) {
37+
const topResult = showResultsArr[0].show;
38+
const posterDiv = document.getElementById('poster');
39+
posterDiv.innerHTML = '';
40+
41+
const imageEl = document.createElement('img');
42+
imageEl.src = topResult.image.original;
43+
imageEl.width = '200';
44+
posterDiv.appendChild(imageEl);
45+
}
46+
47+
function getActors(showId) {
48+
const xmlReq = new XMLHttpRequest();
49+
50+
xmlReq.addEventListener('load', event => {
51+
const response = JSON.parse(event.currentTarget.response);
52+
displayActorHeadshots(response);
53+
});
54+
55+
xmlReq.open('GET', `http://api.tvmaze.com/shows/${showId}/cast`, true);
56+
xmlReq.send();
57+
}
58+
59+
function displayActorHeadshots(castData) {
60+
const actorImagesEl = document.getElementById('actors');
61+
actorImagesEl.innerHTML = '';
62+
63+
for (let castMember of castData) {
64+
const imageEl = document.createElement('img');
65+
imageEl.src = castMember.person.image.original;
66+
imageEl.width = '100';
67+
actorImagesEl.appendChild(imageEl);
68+
}
69+
}
70+
</script>
71+
</body>
72+
</html>

0 commit comments

Comments
 (0)