-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart-quantity.html
More file actions
79 lines (63 loc) · 1.6 KB
/
cart-quantity.html
File metadata and controls
79 lines (63 loc) · 1.6 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<head>
<title>Cart</title>
<style>
button {
display: auto;
margin: 1rem;
font-size: 25px;
}
</style>
</head>
<body>
<button onclick = "document.querySelector('.quantity').innerHTML = `The cart quantity is ${cartQuantity}`">Show Quantity</button>
<button onclick = "
checkMaxQuantity(1); "
>Add to cart</button>
<button onclick = "
checkMaxQuantity(2);"
>+2</button>
<button onclick = "
checkMaxQuantity(3); "
>+3</button>
<button onclick = "
checkMaxQuantity(4);"
>+4</button>
<button onclick = "
checkMaxQuantity(5);"
>+5</button>
<button onclick = "
cartQuantity = 0;
document.querySelector('.quantity').innerHTML = `The cart quantity is ${cartQuantity}`"
>Reset Cart</button>
<button onclick =
"checkMinQuantity(1);"
>Remove from cart</button>
<button onclick = "
checkMinQuantity(2);"
>-2</button>
<button onclick = "
checkMinQuantity(3);"
>-3</button>
<p class = "quantity"></p>
<script>
let cartQuantity = 0;
function checkMaxQuantity(increasedAmount) {
if ((cartQuantity + increasedAmount) > 10) {
alert('The cart is full');
} else {
cartQuantity += increasedAmount;
document.querySelector(".quantity").innerHTML = `The cart quantity is ${cartQuantity}`
}
}
function checkMinQuantity(decreasedAmount) {
if ((cartQuantity - decreasedAmount) < 0) {
alert('The cart is empty');
} else {
cartQuantity -= decreasedAmount;
document.querySelector(".quantity").innerHTML = `The cart quantity is ${cartQuantity}`
}
}
</script>
</body>
</html>