Add number guessing game with HTML, CSS, and JavaScript implementation

This commit is contained in:
vista-man
2025-01-27 20:17:35 +01:00
parent ef1b5f2420
commit 5b2c9b856e
3 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Raad het getal</title>
<script src="raadgetal.js" defer></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Raad het getal</h1>
<p>Voer een getal in tussen 1 en 100:</p>
<input type="number" id="guessInput">
<button onclick="checkGuess()">Gok</button>
<p id="result"></p>
</body>
</html>

View File

@@ -0,0 +1,16 @@
const targetNumber = Math.floor(Math.random() * 100) + 1;
let guess = null;
function checkGuess() {
guess = parseInt(document.getElementById("guessInput").value, 10);
if (guess < targetNumber) {
document.getElementById("result").innerText = "Te laag! Probeer het opnieuw.";
} else if (guess > targetNumber) {
document.getElementById("result").innerText = "Te hoog! Probeer het opnieuw.";
} else if (guess === targetNumber) {
document.getElementById("result").innerText = "Gefeliciteerd! Je hebt het juiste getal geraden.";
} else {
document.getElementById("result").innerText = "Ongeldige invoer. Voer een getal in tussen 1 en 100.";
}
}

View File

@@ -0,0 +1,26 @@
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
margin: 0;
}
h1 {
color: #333;
}
input, button {
padding: 10px;
margin: 5px;
font-size: 16px;
}
#result {
margin-top: 20px;
font-size: 18px;
color: #555;
}