-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_add_javascript.html
More file actions
78 lines (67 loc) · 2.47 KB
/
Copy path3_add_javascript.html
File metadata and controls
78 lines (67 loc) · 2.47 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adding Interactivity with JavaScript</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
button {
padding: 10px 15px;
margin: 5px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>JavaScript Interactive Page</h1>
<p id="welcome-text">Welcome to our interactive page!</p>
<button onclick="changeText()">Change Welcome Text</button>
<button onclick="showAlert()">Click for Alert</button>
<button onclick="changeColor()">Change Background Color</button>
<div>
<h2>Counter: <span id="counter">0</span></h2>
<button onclick="increaseCounter()">Increase Counter</button>
<button onclick="resetCounter()">Reset Counter</button>
</div>
<script>
// STUDENT: Add your JavaScript code below this line
function changeText() {
// Get the paragraph element and change its text
document.getElementById('welcome-text').innerHTML = 'You changed the text! Great job!';
}
function showAlert() {
// Create a popup alert
alert('Hello! This is a JavaScript alert!');
}
function changeColor() {
// Change the background color of the page
const colors = ['#f0f8ff', '#fff0f5', '#f0fff0', '#fff8dc'];
const randomColor = colors[Math.floor(Math.random() * colors.length)];
document.body.style.backgroundColor = randomColor;
}
function increaseCounter() {
// Increase the counter by 1
let currentCount = parseInt(document.getElementById('counter').textContent);
document.getElementById('counter').textContent = currentCount + 1;
}
function resetCounter() {
// Reset the counter to 0
document.getElementById('counter').textContent = '0';
}
// BONUS: Can you create a function that changes the heading color when called?
</script>
</body>
</html>