-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.html
More file actions
125 lines (110 loc) · 4.24 KB
/
widget.html
File metadata and controls
125 lines (110 loc) · 4.24 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Widget</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Fugaz+One&family=Tinos:ital,wght@0,400;0,700;1,400;1,700&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<h3><a href="index.html">Home Page</a></h3>
<img id="canyon" src="image.webp" alt="canyon clicker" width="500" height="300">
<h3>Canyon Clicker</h3>
<p>Click the Image to Earn Points!</p>
<p>Points: <span id="points">0</span></p>
<button id="resetButton">Reset Points</button>
<button id="upgradeButton">Upgrade (Cost: 10 points)</button>
<script>
let clickPoints = 1;
let points = 0;
const pointsDisplay = document.getElementById('points');
const resetButton = document.getElementById('resetButton');
const image = document.querySelector('img');
const upgradeButton = document.createElement('button');
upgradeButton.id = 'upgradeButton';
upgradeButton.textContent = 'Upgrade (Cost: 10 points)';
document.body.appendChild(upgradeButton);
image.addEventListener('click', () => {
points += clickPoints;
pointsDisplay.textContent = points;
});
upgradeButton.addEventListener('click', () => {
if (points >= 10) {
points -= 10;
pointsDisplay.textContent = points;
clickPoints = 5;
console.log('Upgraded! Each click now gives ' + clickPoints + ' points.');
} else {
alert('Not enough points for upgrade!');
}
});
resetButton.addEventListener('click', () => {
points = 0;
pointsDisplay.textContent = points;
});
</script>
<style>
p {
font-size: 35px;
}
h3 {
font-size: 40px;
}
</style>
<label>
Name:
<input id="nameInput" type="text" placeholder="Enter your name">
</label>
<label>
Age:
<input id="ageInput" type="number" min="0" max="120">
</label>
<button id="btnGreet">Greet Me</button>
<div class="output" id="greetingOutput"></div>
</label>
<script>
const nameInput = document.getElementById("nameInput");
const ageInput = document.getElementById("ageInput");
const btnGreet = document.getElementById("btnGreet");
const greetingOutput = document.getElementById("greetingOutput");
btnGreet.addEventListener("click", () => {
// TODO: Display a message like "Hello NAME, you are AGE years old!"
// Challenge: If age < 13, show "You're just a kid!" instead.
let name = nameInput.value;
let age = ageInput.value;
greetingOutput.textContent = "Hello " + name + ", you are " + age +" years old!";
if (age < 13) {
greetingOutput.textContent = "You're just a kid!";
}
})
</script>
<label>
Favorite Color:
<input id="colorInput" type="color" value="#00AAFF">
</label>
<label>
Volume:
<input id="volumeInput" type="range" min="0" max="100" value="50">
</label>
<div class="output" id="colorOutput"></div>
<script>
const colorInput = document.getElementById("colorInput");
const volumeInput = document.getElementById("volumeInput");
const colorOutput = document.getElementById("colorOutput");
function UpdateColorAndVolume(){
let color = colorInput.value;
let volume = volumeInput.value;
colorOutput.style.backgroundColor = color;
colorOutput.textContent = "color: " + color + " | volume: " + volume;
}
colorInput.addEventListener("input", UpdateColorAndVolume)
volumeInput.addEventListener("input", UpdateColorAndVolume)
</script>
</body>
<p>Reset the page to start the game again</p>
</html>