Skip to content

Commit 8ad0d53

Browse files
committed
create starter and finished files for video 70
1 parent b24ff95 commit 8ad0d53

File tree

2 files changed

+83
-66
lines changed

2 files changed

+83
-66
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
async function go() {
36+
console.log('Starting');
37+
await wait(2000);
38+
console.log('running');
39+
await wait(200);
40+
console.log('ending');
41+
}
42+
43+
// go();
44+
45+
async function makeDinner() {
46+
const pizzaPromise1 = makePizza(['pepperoni']);
47+
const pizzaPromise2 = makePizza(['mushrooms']);
48+
const [pep, mush] = await Promise.all([pizzaPromise1, pizzaPromise2]);
49+
console.log(pep, mush);
50+
}
51+
52+
makeDinner();
53+
54+
// // Function declaration
55+
// async function fd() { }
56+
57+
// // arrow function
58+
// const arrowFn = async () => { }
59+
60+
// // call back
61+
// window.addEventListener('click', async function () {
62+
63+
// })
64+
65+
// //
66+
// const person = {
67+
// // method
68+
// sayHi: async function () {
69+
70+
// },
71+
// // method shorthand
72+
// async sayHello() {
73+
74+
// },
75+
// // function property
76+
// sayHey: async () => {
77+
78+
// }
79+
// }
80+
</script>
81+
</body>
82+
83+
</html>

playground/async-await.html

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,7 @@
1010

1111
<body>
1212
<script>
13-
function wait(ms = 0) {
14-
return new Promise((resolve) => {
15-
setTimeout(resolve, ms);
16-
})
17-
}
1813

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-
async function go() {
36-
console.log('Starting');
37-
await wait(2000);
38-
console.log('running');
39-
await wait(200);
40-
console.log('ending');
41-
}
42-
43-
// go();
44-
45-
async function makeDinner() {
46-
const pizzaPromise1 = makePizza(['pepperoni']);
47-
const pizzaPromise2 = makePizza(['mushrooms']);
48-
const [pep, mush] = await Promise.all([pizzaPromise1, pizzaPromise2]);
49-
console.log(pep, mush);
50-
}
51-
52-
makeDinner();
53-
54-
// // Function declaration
55-
// async function fd() { }
56-
57-
// // arrow function
58-
// const arrowFn = async () => { }
59-
60-
// // call back
61-
// window.addEventListener('click', async function () {
62-
63-
// })
64-
65-
// //
66-
// const person = {
67-
// // method
68-
// sayHi: async function () {
69-
70-
// },
71-
// // method shorthand
72-
// async sayHello() {
73-
74-
// },
75-
// // function property
76-
// sayHey: async () => {
77-
78-
// }
79-
// }
8014
</script>
8115
</body>
8216

0 commit comments

Comments
 (0)