Counter

Daily Vehicle Counter

body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f4f4f4;
margin: 50px;
}
h1 {
font-size: 36px;
color: #333;
}
#counter {
font-size: 60px;
color: #ff5733;
margin: 20px 0;
font-weight: bold;
}
button {
font-size: 20px;
padding: 10px 20px;
margin: 10px;
cursor: pointer;
border: none;
background-color: #28a745;
color: white;
border-radius: 5px;
}
button:hover {
background-color: #218838;
}

Daily Vehicle Counter

Number of Vehicles Today:

0


const counterElement = document.getElementById(‘counter’);

function getStoredCount() {
const storedData = localStorage.getItem(“vehicleCount”);
const storedDate = localStorage.getItem(“countDate”);
const today = new Date().toDateString();

if (storedData && storedDate === today) {
return parseInt(storedData);
} else {
localStorage.setItem(“vehicleCount”, 0);
localStorage.setItem(“countDate”, today);
return 0;
}
}

function increaseCount() {
let count = getStoredCount();
count++;
localStorage.setItem(“vehicleCount”, count);
counterElement.textContent = count;
}

function resetCounter() {
localStorage.setItem(“vehicleCount”, 0);
localStorage.setItem(“countDate”, new Date().toDateString());
counterElement.textContent = “0”;
}

function autoResetAtMidnight() {
setInterval(() => {
const now = new Date();
if (now.getHours() === 0 && now.getMinutes() === 0) {
resetCounter();
}
}, 60000);
}

// Load stored count
counterElement.textContent = getStoredCount();
autoResetAtMidnight();