-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (24 loc) · 835 Bytes
/
Copy pathscript.js
File metadata and controls
32 lines (24 loc) · 835 Bytes
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
let clickCount = 0;
function handleClick() {
clickCount++;
updateCounter();
changeButtonColor();
}
function handleReset() {
clickCount = 0;
updateCounter();
changeButtonColor();
}
function updateCounter() {
document.getElementById('click-counter').innerText = clickCount;
}
function changeButtonColor() {
const button = document.getElementById('click-button');
// Define an array of colors
const colors = ['#4CAF50', '#ff9800', '#d12747'];
// Change the background color based on the click count
button.style.backgroundColor = colors[clickCount % colors.length];
}
// Add click event listeners to the buttons
document.getElementById('click-button').addEventListener('click', handleClick);
document.getElementById('reset-button').addEventListener('click', handleReset);