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

Skip to content

Commit cb76bea

Browse files
committed
finished homework w3
1 parent ca5e60b commit cb76bea

File tree

2 files changed

+69
-17
lines changed

2 files changed

+69
-17
lines changed

Week3/MAKEME.md

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@ Let's continue exercising those programming muscles! Go through the following ex
1919

2020
> Inside of your `JavaScript3` fork and inside of the `Week3` 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`.
2121
22-
**Exercise 1: **
22+
**Exercise 1: Promise me to wait**
2323

24-
<!-- This exercise will be about practicing rewriting Promise syntax to async await -->
25-
26-
In this exercise you'll practice refactoring `Promise` syntax into `async/await` + `try/catch` syntax.
24+
In this exercise you'll practice refactoring `Promise` syntax into `async/await` + `try/catch` syntax. Rewrite exercise A & B using `async/await` + `try/catch` syntax.
2725

2826
```js
2927
// Exercise A
30-
31-
32-
// Exercise B
3328
function getData(url) {
3429
fetch(url)
3530
.then(response => response.json)
@@ -38,23 +33,71 @@ function getData(url) {
3833
}
3934

4035
getData('https://randomfox.ca/floof/');
36+
37+
// Exercise B
38+
const arrayOfWords = ['cucumber', 'tomatos', 'avocado'];
39+
40+
const makeAllCaps = array => {
41+
return new Promise((resolve, reject) => {
42+
let capsArray = array.map(word => {
43+
if (typeof word === 'string') {
44+
return word.toUpperCase();
45+
} else {
46+
reject('Error: Not all items in the array are strings!');
47+
}
48+
});
49+
resolve(capsArray);
50+
});
51+
};
52+
53+
makeAllCaps(arrayOfWords)
54+
.then(result => console.log(result))
55+
.catch(error => console.log(error));
56+
```
57+
58+
**Exercise 2: Classify**
59+
60+
In this exercise you'll read a little story. It's your job to turn the characters in it into classes and instantiate the class into the characters you read about!
61+
62+
```md
63+
# STORY
64+
65+
Abdulkareem is a 35 year old man, that lives in Riyadh. He has a wife and 3 children. As a day job he's a construction worker, that makes houses. He likes to eat dates and smoke water pipe.
66+
67+
Abdulkareem has a horse, named Adel. The horse is 15 years old and has the color brown. Usually the horse eats grass or helps transport materials for Abdulkareem.
68+
69+
And they lived happily ever after!
4170
```
4271

43-
**Exercise 2: **
72+
After reading this story, you have to:
73+
74+
- Create a class for Adbulkareem and Adel
75+
- Instantiate those classes to create an Abdulkareem object and Adel object
76+
77+
**Exercise 3: Trivia time!**
4478

45-
<!-- This exercise will be about practicing creating and using classes -->
79+
Don't you just love trivia games? Let's make our own!
4680

47-
**Exercise 3: **
81+
In this exercise you'll make use of the [Open Trivia Database API](https://opentdb.com/). You are going to fetch 5 random trivia questions and then inject them into the DOM, inside of an accordion. It should behave similar to this:
4882

49-
<!-- This exercise will be about practicing -->
83+
![Trivia App](./../assets/trivia-app.gif)
84+
85+
Here are the requirements:
86+
87+
- Create a folder called `trivia-app`, that includes an HTML, CSS and JavaScript file
88+
- Link them all together in the HTML file
89+
- Only provide the basic structure in the HTML file. All other DOM elements are to be created using JavaScript
90+
- No CSS frameworks are allowed!
91+
- Sometimes the strings you get back from the API contains HTML entities (like `&quote;`). Find out a way to turn this into regular text
92+
- Make use of the following endpoint: https://opentdb.com/api.php?amount=5
5093

5194
## **3. Code along**
5295

53-
In this weeks `code along` you'll be building a website that uses the YouTube API to fetch channel data and videos. You'll be creating a search form to change channels and use [OAuth2](https://www.youtube.com/watch?v=CPbvxxslDTU) to login and logout.
96+
In this weeks `code along` you'll be building a Bookmarker application. It'll allow a user to add in URLs of their favorite websites in order to save it into a list.
5497

5598
Happy learning!
5699

57-
- [YouTube API Project with Authentication](https://www.youtube.com/watch?v=r-yxNNO1EI8)
100+
- [BookMarker Application](https://www.youtube.com/watch?v=32qhBZacCNc)
58101

59102
## **4. PROJECT: Hack Your Repo III**
60103

@@ -80,21 +123,30 @@ Next to that you'll refactor your code using the software design principles you'
80123
Here are the requirements:
81124

82125
- Create a separate `.js` for every function you create
83-
- Import all top-level functions into the `script.js` file to execute
126+
- Import all top-level functions into the `script.js` file to execute when the window has loaded
127+
- Rewrite your logic to be as simple as possible. Use loops and logical operators when needed
128+
- Rename your functions and variables to be as semantic as possible
129+
- Store all your JavaScript files, besides `script.js` in a folder called `util` (short for utility functions)
130+
131+
> Utility functions are reusable functions that are made to solve common problems. They are regular functions that perform tasks like: performing a calculation, transform one data type into another or perform a DOM operation.
84132
85133
### 4.2 Add a feature: Pagination
86134

87-
You might have noticed that when a user selects a repository that has many contributors, the page's height becomes bigger and bigger (thus forcing the user to scroll down). Let's change that, by adding pagination!
135+
You might have noticed that when a user selects a repository that has many contributors, the page's height becomes bigger and bigger (thus forcing the user to scroll down). Let's change that by adding pagination!
88136

89137
What is pagination? Take a look at this:
90138

91139
![Pagination Example](https://lorisleiva.com/assets/img/pagination_1.1785fc69.png)
92140

93-
As you can see there are many pages
141+
In the illustration, each number represents a page. You might have seen it before on websites like Amazon, when you're browsing through different products.
142+
143+
We'll replicate this functionality to allow a user to browse through different contributors without have to scroll incessantly.
94144

95145
Here are the requirements:
96146

97-
- Each "page" should contain at max 5 contributors. If the repository selected contains more than 5 contributors, it will get split up unto a different page
147+
- Each "page" should contain at maximum 5 contributors. If the repository selected contains more than 5 contributors, it will get split up unto a different page (and thus create another addition)
148+
- Slice the array into smaller parts and create a new page every time the maximum has been reached
149+
- Allow a user to click from page to page by clicking on the number, or an arrow to go one page forward or backward
98150

99151
Good luck!
100152

assets/trivia-app.gif

324 KB
Loading

0 commit comments

Comments
 (0)