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

Skip to content

Commit c3b1a1c

Browse files
committed
Update week08 homework
1 parent 9982837 commit c3b1a1c

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

β€ŽJavaScript3/Week8/homework.mdβ€Ž

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ Promises creates a **pleasant way of working with asynchronous code**. It will m
55

66
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()`
77

8-
So lets learn some promises :)
98

109
### Movies exercise
10+
This exercise is repetition of array functions.
11+
1112
Fetch movies from this api: `https://gist.githubusercontent.com/pankaj28843/08f397fcea7c760a99206bcb0ae8d0a4/raw/02d8bc9ec9a73e463b13c44df77a87255def5ab9/movies.json`
1213

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
1817

1918
## Promise that resolves after set time
2019
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()
5049
1. Fetch some data from an api.
5150
2. After that data has been fetched, wait 3 seconds
5251
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)
5453

5554
## Visual promise
5655
This task is about visually understanding the difference between Promise.all and calling a promise one at a time.
5756

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!
5958

6059
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.
6160

6261
```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.
6363
moveElement(document.querySelector('li'), {x: 100, y: 100})
6464
.then(() => {
6565
console.log('Element has been moved');
6666
});
6767
```
6868

69-
Your task is to create two functions!
69+
70+
71+
Your task is to create two functions.
7072
- `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**
7173
- `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**
7274

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+
7383
**One by one**
7484

7585
<img alt="One by one" src="assets/one-by-one.gif" width="300" />

β€ŽJavaScript3/Week8/homework/promise-visual/index.htmlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
</ul>
1919
<span>πŸ‘</span>
2020
</main>
21-
<script src="move-box.js"></script>
21+
<script src="move-element.js"></script>
2222
<script src="main.js"></script>
2323
</body>
File renamed without changes.

0 commit comments

Comments
Β (0)