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

Skip to content

Commit 66633a7

Browse files
authored
Merge pull request HackYourFuture-CPH#87 from HackYourFuture-CPH/week8-updates
Week8 updates
2 parents b5fe0e6 + 0fb61f7 commit 66633a7

File tree

14 files changed

+274
-563
lines changed

14 files changed

+274
-563
lines changed

JavaScript1/Week3/homework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Use this function to add some songs to your playlist!
158158
#### Improving our application *optional*
159159
What if there are multiple songs with the same name? Then we have problems in our `getSongByTitle` function! Instead of returning a song, return an array of songs that match the title parameter.
160160

161-
What is a user had multiple playlists? How could we accomodate that? Either describe how to fix this problem or make some code!
161+
What if a user had multiple playlists? How could we accomodate that? Either describe how to fix this problem or make some code!
162162

163163
![boombox](https://media.giphy.com/media/NkkKrHU2wAin6/giphy.gif)
164164

JavaScript2/Week6/readme.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,24 @@ const fastCarBrands = cars
124124
.map(car => car.brand);
125125
```
126126

127-
This part:
128127
```js
129128
const fastCars = cars
130129
.filter(car => car.speed > 60);
130+
131+
// fastCars is an array! Arrays we can call .map on, so why not do it in one go!?
131132
```
132-
Returns an array of objects (that represent fast cars). We know that we can call filter on an array, doing that we get the chaining of methods.
133+
Calling the `filter` function, returns an array (in our case an array of objects, that represent fast cars). We know that we can call `.map` on an array, doing that we get the chaining of methods.
133134

134135
The principal behind is exactly the same as in this example:
135136

136137
```js
137-
"BENJAMIN".toLowerCase().endsWith('n');
138+
const doesBenjaminEndWithN = "BENJAMIN".toLowerCase().endsWith('n');
139+
140+
// We can also write that as:
141+
doesBenjaminEndWithNFormatted = "BENJAMIN"
142+
.toLowerCase() // <-- toLowerCase returns a string!
143+
.endsWith('n'); // <-- That we can call .endsWith on!
138144
```
139145

140-
We are chaining methods on the return of the previous function's return value
146+
We are chaining methods on the return of the previous function's return value!
147+
653 KB
Loading
766 KB
Loading

JavaScript3/Week8/homework.md

Lines changed: 30 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,21 @@ Since promises is becoming standard in javascript, new browser api's use promise
77

88
So lets learn some promises :)
99

10-
## Warmup exercises
11-
We will start with some **abstract tasks** first and then get into a concrete task in the end.
12-
13-
## Promise that resolves after set time
14-
Create a function that has one parameter: `millisecondsToResolve`. **Calling this function** will **return a promise** that resolves after the millisecondsToResolve has passed.
15-
16-
Here is an example: `notThisFunctionName(3000)` will return a promise that resolves after 3000 milliseconds.
17-
18-
Use the `notThisFunctionName` to log out the string `I am called asynchronously` after 6000 milliseconds.
19-
20-
## Exercise 2
10+
### Movies exercise
2111
Fetch movies from this api: `https://gist.githubusercontent.com/pankaj28843/08f397fcea7c760a99206bcb0ae8d0a4/raw/02d8bc9ec9a73e463b13c44df77a87255def5ab9/movies.json`
2212

2313
1. Create an array called long movies that contain an array of long movies. A long movie has a running time of larger than 7000
24-
1. Create an array called longMovieTitles. That contain only the titles of the long movies.
25-
1. Log out an array of bad movies
26-
1. Log out an array of bad movies since year 2000
27-
1. only log the titles of the bad movies since year 2000
14+
2. Create an array called longMovieTitles. That contain only the titles of the long movies.
15+
3. Log out an array of bad movies
16+
4. Log out an array of bad movies since year 2000
17+
5. only log the titles of the bad movies since year 2000
2818

29-
## Fetching and waiting
30-
Only using promises
31-
1. Fetch some data from an api.
32-
1. After that data has been fetched, wait 3 seconds
33-
1. Log out the data from the api
34-
1. Now do all of these things using chaining
19+
## Promise that resolves after set time
20+
Create a function that has one parameter: `resolveAfter`. **Calling this function** will **return a promise** that resolves after the `resolveAfter` seconds has passed.
21+
22+
Here is an example: `makeUpYourOwnFunctionName(3)` will return a promise that resolves after 3 seconds.
23+
24+
Use the `makeUpYourOwnFunctionName` to log out the string `I am called asynchronously` after 6 seconds.
3525

3626
## Rewrite time
3727
Rewrite [setTimeout](https://developer.mozilla.org/ro/docs/Web/API/window.setTimeout) and [navigator.geolocation.getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API#JavaScript_Content) to promises. So instead of using [setTimeout](https://developer.mozilla.org/ro/docs/Web/API/window.setTimeout) and [navigator.geolocation.getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API#JavaScript_Content) with callbacks, use it as a promise.
@@ -55,57 +45,38 @@ getCurrentLocation()
5545
});
5646
```
5747

58-
## Thumbs up or thumbs down
59-
Lets build a website where people can say thumbs up or thumbs down to diffeent things.
60-
61-
![Demo](homework/demo.gif)
62-
63-
If you go into the [homework folder](homework) there is some html, css and some js. If you clone down the javascript repo, then you can simply copy the files into your hyf-homework js3 week 2 folder.
64-
65-
You will be working in the index.js file.
66-
67-
### Manually create functionality
68-
What we want to happen when a button is clicked is the following:
69-
1. The `li` in the top of the `ul` should get a `transform:translateX(1000px)`. That will translate the `li` to the right out of the window. This indicates that the user has given a thumbs up to what the `li` element contains. When the `li` has been translated out we dont see any `li`. Thats because the next `li` has `opacity: 0;`. Lets fix that in the next step.
70-
1. Lets show the next `li`: The next `li` (the second `li` in the `ul`) should become visible. Do that by giving it the following css attributes: `opacity: 1; transform: scale(1);` This will animate the next `li` element into view.
71-
72-
Do these steps two **manually using the inspector** simply setting the style of the relevant elements. **Nothing to hand in here**, its just simply to give you a feeling for the application.
48+
## Fetching and waiting
49+
**Only using promises**
50+
1. Fetch some data from an api.
51+
2. After that data has been fetched, wait 3 seconds
52+
3. Log out the data from the api
53+
4. Now do all of these things using [chaining](readme.md#promise-chaining)
7354

74-
### Getting to js
75-
Now we have a feeling for what should happen when the thumbs up button is clicked: **Animate `li` out, then animate next `li` into view**
55+
## Visual promise
56+
This task is about visually understanding the difference between Promise.all and calling a promise one at a time.
7657

77-
The very detail oriented students probably saw the keyword **then** in the previous sentence! Hmm that sound just like a promise:
78-
- Do something (animate `li` out)
79-
- **then** do something else (animate next `li` into view)
58+
If you go into the [promise-visual homework folder](homework/promise-visual) there is some html, css and some js. If you clone down the javascript repo, then you can simply copy the files into your hyf-homework js3 week 2 folder. Dont modify move-box.js, only work in main.js!
8059

81-
Lets create a function called `animateLiOut`. This function should animate the `li` out and **return a promise** that resolves after the animation of the first `li` is done. (how long time does it take for the `li` to animate out?) What function can we use to wait for some given time in js?
60+
There is a function available to you called `moveElement`. It moves an element to a new position and returns a promise. `moveElement` takes a `DOM element` and an `object` specifying the `x` and `y` of the new position. It then returns a `promise` that resolves after the `DOM element` has been moved.
8261

83-
Pseudo code of the function
8462
```js
85-
animateLiOut()
63+
moveElement(document.querySelector('li'), {x: 100, y: 100})
8664
.then(() => {
87-
// this callback function is first called when the li is out of view!
88-
89-
// Now lets animate the next li into view
90-
animateNextLiIntoView();
65+
console.log('Element has been moved');
9166
});
9267
```
9368

94-
### Improving the application
95-
Now when we press the thumbs up button: the first `li` is animated out and the next one comes into view. But what about when we **press the button again**? Lets create the functionality that keeps animating the next `li` out, we now need some kind of index to keep track of which `li` has been animated out. And what if we **press the thumbs down button**, then the `li` should be animated out of view but **to the left not to the right**. Lets also create that functionality.
96-
97-
### Personalise the application
98-
Right now the `li` elements just have the text Thing 1, Thing 2 which is super boring! Now you have to give it a **personal touch**!
69+
Your task is to create two functions!
70+
- `translateOneByOne` - Should translate the circles one at a time from their **random start position** to their **target**. Log something out **after each element has been moved**
71+
- `translateAllAtOnce` - Should translate all the circles at the same time from their **random start position** to their **target**. Log out something **after all elements have been moved**
9972

100-
You decide what we are giving thumbs up or down to. Maybe its music tracks, food dishes, movies or danish traditions, **you decide!**
73+
**One by one**
10174

102-
Create an `array` of `objects` in js that represents what we are interacting with. Using that `array` of `objects`, build the `li's` and insert them into the `ul`. The `li's` could contain a h1, a span, maybe an image, you decide here, as long as it is built from the `array` of `objects`.
75+
<img alt="One by one" src="assets/one-by-one.gif" width="300" />
10376

104-
### Improve improve imporve *optional*
105-
- What if we instead of creating our own `array` of `objects` fetch some data from an [api](https://github.com/toddmotto/public-apis) and use that data to render our `li's`
106-
- Interaction with the keyboard arrows
107-
- Super duper hard mode: swipe the card
77+
**All at one**
10878

79+
<img alt="All at one" src="assets/all-at-once.gif" width="300" />
10980

11081
## Feedback giving time!
11182
Find a student to give feedback using this site: https://hyf-peer-review.herokuapp.com/
-4.77 MB
Binary file not shown.

0 commit comments

Comments
 (0)