-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
35 lines (29 loc) · 890 Bytes
/
Copy pathmain.js
File metadata and controls
35 lines (29 loc) · 890 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
33
34
35
// main.js
// --- 1. Core Variables & State ---
const userLocation = "Boulder, CO";
let visitCount = 0;
// --- 2. DOM Elements ---
const greetingEl = document.getElementById('greeting');
const counterEl = document.getElementById('visit-counter');
const actionBtn = document.getElementById('action-button');
// --- 3. Functions ---
function updateGreeting() {
if (greetingEl) {
greetingEl.textContent = `Welcome to the app in ${userLocation}!`;
}
}
function incrementCounter() {
visitCount++;
if (counterEl) {
counterEl.textContent = `Button clicked ${visitCount} times.`;
}
}
// --- 4. Event Listeners & Initialization ---
function init() {
updateGreeting();
if (actionBtn) {
actionBtn.addEventListener('click', incrementCounter);
}
}
// Run setup when the page fully loads
document.addEventListener('DOMContentLoaded', init);