-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy path09_solve.html
More file actions
41 lines (38 loc) · 1.13 KB
/
09_solve.html
File metadata and controls
41 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="order">
<div class="item"></div>
<div class="price"></div>
</div>
<button class="btn">Place Order</button>
<script>
let order = {
item: "ToothBrush",
cost: '10rs'
};
async function placeOrder(order, delay) {
return await new Promise(resolve => {
setTimeout(() => {
localStorage.setItem('Order', JSON.stringify(order));
resolve("Order Placed");
}, delay * 1000);
})
}
document.querySelector(".btn").addEventListener("click", () => {
let delay = Math.random() * 6 + 1;
placeOrder(order, delay).then(confirmation => {
document.querySelector(".btn").innerHTML = confirmation;
let data = JSON.parse(localStorage.getItem("Order"));
document.querySelector(".item").innerHTML = data.item;
document.querySelector(".price").innerHTML = data.cost;
});
})
</script>
</body>
</html>