File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -302,22 +302,25 @@ Using promises
302
302
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.
303
303
304
304
## 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:
306
306
307
307
``` 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
+ });
317
320
318
321
```
319
322
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
321
324
322
325
## Exercise 5
323
326
Using async await
You can’t perform that action at this time.
0 commit comments