mirror of
https://github.com/Alvin-Zilverstand/ict-algemeen-opdrachten.git
synced 2026-11-21 13:43:06 +01:00
Add number guessing game with HTML, CSS, and JavaScript implementation
This commit is contained in:
1 parent
ef1b5f2420
commit
5b2c9b856e
3 files changed
+59
No files matched your search
@@ -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>
|
||||
@@ -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.";
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user