-
Notifications
You must be signed in to change notification settings - Fork 0
/
amazon-card.html
48 lines (46 loc) · 1.24 KB
/
amazon-card.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>amazon card</title>
</head>
<body>
<h1>amazon card</h1>
<p>order below 40 charges shipping</p>
<p>order's above 40 will get free shipping</p>
<input
type="text"
class="input-cost"
placeholder="cost of product"
onkeydown="
handle_key_event(event)
"
/>
<button class="js-calculate" onclick="calculate_shipping();">
calculate
</button>
<p class="cost_representer"></p>
<script>
function handle_key_event(event) {
if (event.key === "Enter") {
calculate_shipping();
}
}
function calculate_shipping() {
const inputElement = document.querySelector(".input-cost");
let cost = Number(inputElement.value);
if (cost <= 40) {
cost = cost + 10;
document.querySelector(
".cost_representer"
).innerHTML = ` total amount ${cost}`;
} else {
document.querySelector(
".cost_representer"
).innerHTML = ` congratulations free shipping ${cost}`;
}
}
</script>
</body>
</html>