<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tebak Angka</title>
<!-- <link rel="stylesheet" href="style.css"> -->
<style>
/* style.css */
body {
font-family: "Arial", sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(135deg, #71b7e6, #9b59b6);
margin: 0;
color: #333;
}
.game-container {
background-color: #fff;
padding: 40px;
border-radius: 15px;
box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
text-align: center;
max-width: 400px;
width: 100%;
}
h1 {
font-size: 2em;
margin-bottom: 20px;
color: #333;
}
p {
font-size: 1.2em;
}
input[type="number"] {
width: calc(100% - 22px);
padding: 10px;
margin: 15px 0;
font-size: 1em;
border: 2px solid #ddd;
border-radius: 5px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
transition: border-color 0.3s;
}
input[type="number"]:focus {
border-color: #9b59b6;
outline: none;
}
button {
padding: 10px 20px;
font-size: 1em;
color: #fff;
background-color: #9b59b6;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s, box-shadow 0.3s;
}
button:hover {
background-color: #8e44ad;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
#feedback {
margin-top: 20px;
font-weight: bold;
font-size: 1.2em;
}
</style>
</head>
<body>
<div class="game-container">
<h1>Game Tebak Angka</h1>
<p>Tebak angka antara 1 dan 100</p>
<input type="number" id="guessInput" placeholder="Masukkan tebakan..." />
<button id="guessButton">Tebak</button>
<p id="feedback"></p>
</div>
<!-- <script src="script.js"></script> -->
<script>
// script.js
document.addEventListener("DOMContentLoaded", function () {
const randomNumber = Math.floor(Math.random() * 100) + 1;
const guessInput = document.getElementById("guessInput");
const guessButton = document.getElementById("guessButton");
const feedback = document.getElementById("feedback");
guessButton.addEventListener("click", function () {
const userGuess = parseInt(guessInput.value);
if (isNaN(userGuess)) {
feedback.textContent = "Masukkan angka yang valid!";
feedback.style.color = "red";
return;
}
if (userGuess < randomNumber) {
feedback.textContent = "Terlalu rendah! Coba lagi.";
feedback.style.color = "orange";
} else if (userGuess > randomNumber) {
feedback.textContent = "Terlalu tinggi! Coba lagi.";
feedback.style.color = "orange";
} else {
feedback.textContent = "Selamat! Tebakanmu benar!";
feedback.style.color = "green";
}
});
});
</script>
</body>
</html>