-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09-dom-projects.html
54 lines (38 loc) · 1.13 KB
/
09-dom-projects.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
<!DOCTYPE html>
<html>
<head>
<title>DOM Projects</title>
<style>
</style>
</head>
<body>
<p>YouTube Subscribe Button</p>
<button onclick="subscribe();
" class="js-sub-button"> Subscribe</button>
<p> Amazon Shipping Calculator </p>
<p> Orders under $40 </p>
<input placeholder="Cost of order" class="js-cost-input" onkeydown="handleCostKeydown(event);">
<button onclick="
calculateTotal();"> Calculate</button>
<p class="js-total-cost"> </p>
<script>
function handleCostKeydown(event) {
if (event.key === 'Enter') {calculateTotal();}
}
function subscribe() {
const subButtonLM = document.querySelector('.js-sub-button');
if (subButtonLM.innerText === 'Subscribe') { subButtonLM.innerHTML = 'Subscribed' }
else { subButtonLM.innerHTML = 'Subscribe' }
}
function calculateTotal() {
const inputElement = document.querySelector('.js-cost-input');
let cost = Number(inputElement.value);
if (cost < 40) { cost = cost + 10; }
else {
cost = cost;
}
document.querySelector('.js-total-cost').innerHTML = `$${cost}`;
};
</script>
</body>
</html>