You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: JavaScript3/Week8/homework.md
+19-9Lines changed: 19 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,15 @@ Promises creates a **pleasant way of working with asynchronous code**. It will m
5
5
6
6
Since promises is becoming standard in javascript, new browser api's use promises for interacting with them. `getUserMedia` for accessing webcam, `Navigator.getBattery()` for getting battery level, `Bluetooth.requestDevice()`, `serviceWorker` or `USB.requestDevice()`
7
7
8
-
So lets learn some promises :)
9
8
10
9
### Movies exercise
10
+
This exercise is repetition of array functions.
11
+
11
12
Fetch movies from this api: `https://gist.githubusercontent.com/pankaj28843/08f397fcea7c760a99206bcb0ae8d0a4/raw/02d8bc9ec9a73e463b13c44df77a87255def5ab9/movies.json`
12
13
13
-
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
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
14
+
1. Create an array of bad movies
15
+
2. Creat an array of bad movies since year 2000
16
+
3. Create an array of the titles of the bad movies since year 2000
18
17
19
18
## Promise that resolves after set time
20
19
Create a function that has one parameter: `resolveAfter`. **Calling this function** will **return a promise** that resolves after the `resolveAfter` seconds has passed.
@@ -50,26 +49,37 @@ getCurrentLocation()
50
49
1. Fetch some data from an api.
51
50
2. After that data has been fetched, wait 3 seconds
52
51
3. Log out the data from the api
53
-
4. Now do all of these things using [chaining](readme.md#promise-chaining)
52
+
4.*Optional*Now do all of these things using [chaining](readme.md#promise-chaining)
54
53
55
54
## Visual promise
56
55
This task is about visually understanding the difference between Promise.all and calling a promise one at a time.
57
56
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!
57
+
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-element.js, only work in main.js!
59
58
60
59
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.
61
60
62
61
```js
62
+
// This code will move the li to the position 100, 100. Calling moveElement will return a promise that resolves after the li element has been moved.
-`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
73
-`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**
72
74
75
+
Test that the functions works as intended before submitting homework.
76
+
77
+
```
78
+
Red circle target: x: 20px, y: 300px;
79
+
Blue circle target: x: 400px, y: 300px;
80
+
Green circle target: x: 400px, y: 20px;
81
+
```
82
+
73
83
**One by one**
74
84
75
85
<imgalt="One by one"src="assets/one-by-one.gif"width="300" />
0 commit comments