<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>カウンターアプリ</title>
<style>
body {
font-family: sans-serif;
padding: 20px;
}
.container {
max-width: 400px;
margin: 0 auto;
text-align: center;
}
#count {
font-size: 72px;
font-weight: bold;
color: #333;
margin: 30px 0;
}
.buttons {
display: flex;
gap: 10px;
justify-content: center;
}
button {
padding: 15px 30px;
font-size: 24px;
cursor: pointer;
border: none;
border-radius: 4px;
transition: all 0.2s;
}
#incrementButton {
background-color: #4CAF50;
color: white;
}
#incrementButton:hover {
background-color: #45a049;
}
#decrementButton {
background-color: #f44336;
color: white;
}
#decrementButton:hover {
background-color: #da190b;
}
</style>
</head>
<body>
<div class="container">
<h1>カウンターアプリ</h1>
<div id="count">0</div>
<div class="buttons">
<button id="decrementButton">-1</button>
<button id="incrementButton">+1</button>
</div>
</div>
<script>
const incrementButton = document.querySelector("#incrementButton");
const decrementButton = document.querySelector("#decrementButton");
const countElement = document.querySelector("#count");
let count = 0;
incrementButton.addEventListener("click", () => {
count = count + 1;
countElement.textContent = count;
});
decrementButton.addEventListener("click", () => {
count = count - 1;
countElement.textContent = count;
});
</script>
</body>
</html>