-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.html
161 lines (145 loc) · 6.41 KB
/
cart.html
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Cart</title>
<script defer="" src="/cart.a48cb30d.js"></script>
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-sm-12 mb-5">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="works.html">works</a></li>
<li class="breadcrumb-item active" aria-current="page">Cart</li>
</ol>
</nav>
</div>
<div class="col-sm-12 col-md-4">
<h2><i class="fas fa-shopping-cart"></i> Cart Items</h2>
<form id="cartForm">
<div class="mb-3">
<label for="name" class="form-label">Your Name</label>
<input type="text" class="form-control" id="name" required="">
</div>
<div class="mb-3">
<label for="item1" class="form-label">Item 1 Amount</label>
<input type="number" class="form-control" id="item1" required="">
</div>
<div class="mb-3">
<label for="item2" class="form-label">Item 2 Amount</label>
<input type="number" class="form-control" id="item2" required="">
</div>
<div class="mb-3">
<label for="item3" class="form-label">Item 3 Amount</label>
<input type="number" class="form-control" id="item3" required="">
</div>
<button type="submit" class="btn btn-primary w-100 mb-5">Submit</button>
</form>
</div>
<div class="col-sm-12 col-md-4">
<h2><i class="fas fa-clipboard-list"></i> Cart Details</h2>
<p><i class="far fa-user"></i> <strong id="namePlaceHolder"></strong> Cart.</p>
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
Item 1 Amount
<div>
<span id="item-1-details">343</span>
<i class="fas fa-rupee-sign"></i>
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Item 2 Amount
<div>
<span id="item-2-details">2</span>
<i class="fas fa-rupee-sign"></i>
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Item 3 Amount
<div>
<span id="item-3-details">1</span>
<i class="fas fa-rupee-sign"></i>
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Total Cart Value
<div>
<span id="total-cart-value">1</span>
<i class="fas fa-rupee-sign"></i>
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Highest Cart Item Value
<div>
<span id="highest-cart-value">1</span>
<i class="fas fa-rupee-sign"></i>
</div>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
Lowest Cart Item Value
<div>
<span id="lowest-cart-value">1</span>
<i class="fas fa-rupee-sign"></i>
</div>
</li>
</ul>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script>var cartFormElement = document.getElementById('cartForm');
function addNameToDetails() {
var nameElement = document.getElementById('name');
let formattedName = nameElement.value.toUpperCase() + "'s";
document.getElementById('namePlaceHolder').innerText = formattedName;
}
function addItemsAmountsToDetails() {
document.getElementById('item-1-details').innerText = document.getElementById('item1').value;
document.getElementById('item-2-details').innerText = document.getElementById('item2').value;
document.getElementById('item-3-details').innerText = document.getElementById('item3').value;
}
function addTotalCartValueToDetails() {
let totalValue = parseInt(document.getElementById('item1').value) + parseInt(document.getElementById('item2').value) + parseInt(document.getElementById('item3').value);
console.log(totalValue);
document.getElementById('total-cart-value').innerText = totalValue;
}
function findTheHighestAndLowestCartValues() {
// let us build the array with values ['12','67' , '5847']
let item1Value = document.getElementById('item1').value;
let item2Value = document.getElementById('item2').value;
let item3Value = document.getElementById('item3').value;
console.log(item1Value, item2Value, item3Value);
// let cartItems = [];
let cartItems = [
item1Value,
item2Value,
item3Value
];
console.log(cartItems);
let highestValue = parseInt(cartItems[0]);
for(let index = 0; index < cartItems.length; index++)if (parseInt(cartItems[index]) > highestValue) highestValue = parseInt(cartItems[index]);
console.log('Highest value:', highestValue);
let lowestValue = parseInt(cartItems[0]);
for(let index1 = 0; index1 < cartItems.length; index1++)if (parseInt(cartItems[index1]) < lowestValue) lowestValue = parseInt(cartItems[index1]);
console.log('Lowest value:', lowestValue);
document.getElementById('highest-cart-value').innerText = highestValue;
document.getElementById('lowest-cart-value').innerText = lowestValue;
}
cartFormElement.addEventListener('submit', function(event) {
// console.log(event);
event.preventDefault();
console.log('hello');
addNameToDetails();
addItemsAmountsToDetails();
addTotalCartValueToDetails();
findTheHighestAndLowestCartValues();
});
</script>
</body>
</html>