-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09-dom-projects.html
More file actions
42 lines (39 loc) · 1.18 KB
/
09-dom-projects.html
File metadata and controls
42 lines (39 loc) · 1.18 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
<!DOCTYPE html>
<html>
<head>
<title>Dom project</title>
</head>
<body>
<p>Youtube subscribe button</p>
<button onclick="subscribe()" class="js-subscribe-button">Subscribe</button>
<p>Amazon Shipping Calculator</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 CalculateTotal() {
const inputElement = document.querySelector('.js-cost-input');
let cost = Number(inputElement.value);
if (cost < 40) {
cost = cost + 10;
}
document.querySelector('.js-total-cost')
.innerHTML = `$${cost}`;
}
function subscribe() {
const buttonElement = document.querySelector('.js-subscribe-button');
if (buttonElement.innerText === 'Subscribe') {
buttonElement.innerHTML = 'Subscribed';
} else {
buttonElement.innerHTML = 'Subscribe';
}
}
</script>
</body>
</html>