File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta name ="viewport " content ="width=device-width,initial-scale=1.0 ">
7+ < title > Async Await</ title >
8+ < link rel ="stylesheet " href ="../base.css ">
9+ </ head >
10+
11+ < body >
12+ < script >
13+ function wait ( ms = 0 ) {
14+ return new Promise ( ( resolve ) => {
15+ setTimeout ( resolve , ms ) ;
16+ } )
17+ }
18+
19+ function makePizza ( toppings = [ ] ) {
20+ return new Promise ( function ( resolve , reject ) {
21+ // reject if people try with pineapple
22+ if ( toppings . includes ( 'pineapple' ) ) {
23+ reject ( 'Seriously? Get out 🍍' ) ;
24+ }
25+ const amountOfTimeToBake = 500 + ( toppings . length * 200 ) ;
26+ // wait 1 second for the pizza to cook:
27+ setTimeout ( function ( ) {
28+ // when you are ready, you can resolve this promise
29+ resolve ( `Here is your pizza 🍕 with the toppings ${ toppings . join ( ' ' ) } ` ) ;
30+ } , amountOfTimeToBake ) ;
31+ // if something went wrong, we can reject this promise;
32+ } ) ;
33+ }
34+
35+ </ script >
36+ </ body >
37+
38+ </ html >
You can’t perform that action at this time.
0 commit comments