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

Skip to content

Commit b3a2f34

Browse files
authored
Update lesson-plan.md
A more clear example4
1 parent acbfb50 commit b3a2f34

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

javascript3/week2/lesson-plan.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,25 @@ Using promises
302302
2. Now make the promise fail by rejecting it with an error message instead of resolving it, and log the error message to the console.
303303

304304
## Exercise 4
305-
Create a function that returns a promise, that i can use like this:
305+
Create a function that returns a promise, that you can use like this:
306306

307307
```js
308-
// getLoggedInUsers should wait 5 seconds before it resolves with the users!
309-
// Sometimes it should resolve and sometimes it should reject.
310-
// Look into Math.random
311-
getLoggedInUsers()
312-
.then(users => {
313-
console.log(users); // ['benna', 'magdy', 'carolina']
314-
}).catch(error => {
315-
console.log(error);
316-
});
308+
// YesNoFail4Seconds should wait 4 seconds before it does one of the following 3 things:
309+
// resolves with a yes
310+
// resolves with a no
311+
// or rejects
312+
// Look into Math.random()
313+
YesNoFail4Seconds()
314+
.then((data) => {
315+
console.log(`The answer is ${data}`);
316+
})
317+
.catch((error) => {
318+
console.log(error);
319+
});
317320

318321
```
319322

320-
The above example show how to consume the promise using promises. Now try consume the `getLoggedInUsers` using async/await
323+
The above example show how to consume the promise using promises. Now try consume the `YesNoFail4Seconds` using async/await
321324

322325
## Exercise 5
323326
Using async await

0 commit comments

Comments
 (0)