mirror of
https://github.com/Alvin-Zilverstand/ict-algemeen-opdrachten.git
synced 2026-03-06 13:23:58 +01:00
Add number guessing game with HTML, CSS, and JavaScript implementation
This commit is contained in:
17
JavaScript/raad het getal/index.html
Normal file
17
JavaScript/raad het getal/index.html
Normal 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>
|
||||||
16
JavaScript/raad het getal/raadgetal.js
Normal file
16
JavaScript/raad het getal/raadgetal.js
Normal 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.";
|
||||||
|
}
|
||||||
|
}
|
||||||
26
JavaScript/raad het getal/style.css
Normal file
26
JavaScript/raad het getal/style.css
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user