Repository navigation
Expand file tree
/
Copy path09-exercises.html
More file actions
52 lines (46 loc) · 1.58 KB
/
Copy path09-exercises.html
File metadata and controls
52 lines (46 loc) · 1.58 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
<!DOCTYPE html>
<html>
<head>
<title>Amazon Shipping Calculator</title>
</head>
<body>
<p>Amazon Shipping Calculator</p>
<p>Orders under $40 = +$10 shipping.</p>
<p>Orders over $40 = FREE shipping.</p>
<input placeholder="Cost of Order"
class = "js-cost-input" onkeydown="
handleCostkeydown(event);
">
<button onclick="
calculateTotal();
">Calculate</button>
<p class = "js-final-cost"></p>
<input style="border-width: 2.5px;
border-color: blue;
border-radius: 3px;
" onkeyup="handlekeyup(event)" class="js-input">
<p class ="js-copy"></p>
<script>
function handlekeyup(event){
const inputElement = document.querySelector('.js-input');
document.querySelector('.js-copy').innerHTML = inputElement.value;
}
function handleCostkeydown(event){
if (event.key === 'Enter'){
calculateTotal();
}
}
function calculateTotal(){
const inputElement = document.querySelector('.js-cost-input');
let cost = inputElement.value;
cost = Number(cost);
console.log(cost);
if (cost < 40){
cost += 10;
cost = parseFloat(cost.toFixed(2));
}
document.querySelector('.js-final-cost').innerHTML = `$${cost}`;
}
</script>
</body>
</html>