-
Notifications
You must be signed in to change notification settings - Fork 0
/
09-dom-projects.html
56 lines (48 loc) · 1.56 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
55
56
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DOM Projects</title>
</head>
<body>
<p> YouTube Subscribe Button</p>
<button onclick="subscribe()" class="js-subscribe-button">Subscribe</button>
<p>Amazon Shipping Calculator</p>
<label>
<input placeholder="Cost of order" class="js-cost-input" onkeydown="handleCostKeyDown(event)">
</label>
<button onclick="calculateTotal();">Calculate</button>
<p class="js-total-cost"></p>
<script>
String(25) // Type Coercion
console.log('25' - 5);
console.log('25' + 5);
// Window object represents the browser
window.document // represents webpage
window.console.log('window') // represents console
window.alert() // represents pop-up
function handleCostKeyDown(event) {
if (event.key === 'Enter') {
calculateTotal();
}
}
function calculateTotal() {
const inputElement = document.querySelector('.js-cost-input');
let cost = Number(inputElement.value); // value will be a string (if it needs to be a number -> convert)
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.innerText = 'Subscribed';
} else {
buttonElement.innerText = 'Subscribe';
}
}
</script>
</body>
</html>