<div class="counter-card">
<h1>Counter</h1>
<p id="count-display">0</p>
<div class="buttons">
<button id="decrement-btn">-</button>
<button id="increment-btn">+</button>
</div>
</div>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: sans-serif;
background-color: #f0f2f5;
margin: 0;
}
.counter-card {
background: white;
padding: 30px 40px;
border-radius: 15px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
text-align: center;
}
#count-display {
font-size: 4rem;
margin: 10px 0;
color: #333;
}
button {
font-size: 2rem;
padding: 5px 20px;
margin: 0 10px;
border-radius: 8px;
border: 1px solid #ccc;
cursor: pointer;
background-color: #e9ecef;
transition: background-color 0.2s;
}
button:hover {
background-color: #dee2e6;
}
const countDisplay = document.getElementById('count-display');
const incrementBtn = document.getElementById('increment-btn');
const decrementBtn = document.getElementById('decrement-btn');
let count = 0;
function updateDisplay() {
countDisplay.textContent = count;
}
incrementBtn.addEventListener('click', () => {
count++;
updateDisplay();
});
decrementBtn.addEventListener('click', () => {
count--;
updateDisplay();
});