File tree 1 file changed +71
-0
lines changed
promises-async-await/v2/async-await
1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 " />
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7
+ < title > Async Await</ title >
8
+ < style >
9
+ * {
10
+ margin : 0 ;
11
+ padding : 0 ;
12
+ box-sizing : border-box;
13
+ }
14
+ div {
15
+ width : 400px ;
16
+ margin : 120px auto;
17
+ text-align : center;
18
+ }
19
+ div ul {
20
+ list-style : none;
21
+ margin : 20px 0 ;
22
+ }
23
+ p {
24
+ font-size : 20px ;
25
+ }
26
+ button {
27
+ margin-top : 10px ;
28
+ }
29
+ </ style >
30
+ </ head >
31
+ < body >
32
+ < div >
33
+ < p id ="info "> Confirm your order</ p >
34
+ < ul >
35
+ < li > Games - 10$</ li >
36
+ < li > Snacks - 80$</ li >
37
+ < li > Total - 90$</ li >
38
+ </ ul >
39
+ < form action ="">
40
+ < button onclick ="submitForm() "> Submit</ button >
41
+ </ form >
42
+ </ div >
43
+ < script src ="vendor.js "> </ script >
44
+
45
+ < script >
46
+ const info = document . querySelector ( "#info" ) ;
47
+ window . submitForm = async function ( ) {
48
+ event . preventDefault ( ) ;
49
+ console . log ( "Submitting info to the vendors" ) ;
50
+
51
+ let orderResponse = null ;
52
+
53
+ const creditResponse = await creditValidAPI . makeAPIRequest ( ) ;
54
+ console . log ( creditResponse ) ;
55
+ try {
56
+ orderResponse = await placeOrderAPI . makeAPIRequest ( ) ;
57
+ console . log ( orderResponse ) ;
58
+ } catch ( error ) {
59
+ info . innerHTML = "order is not placed" ;
60
+ }
61
+
62
+ const supplierResponse = await contactSupplierAPI . makeAPIRequest ( ) ;
63
+ console . log ( supplierResponse ) ;
64
+ if ( supplierResponse . contacted ) {
65
+ info . innerHTML = "order placed!" ;
66
+ document . querySelector ( "button" ) . innerText = "Submitted" ;
67
+ }
68
+ } ;
69
+ </ script >
70
+ </ body >
71
+ </ html >
You can’t perform that action at this time.
0 commit comments