forked from truon/SimT
Transférer les fichiers vers 'GutenTag'
This commit is contained in:
parent
8075a98888
commit
80bdb29e9a
3 changed files with 78 additions and 0 deletions
7
GutenTag/test.css
Normal file
7
GutenTag/test.css
Normal file
|
@ -0,0 +1,7 @@
|
|||
.center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.biggerSize {
|
||||
font-size: 200%;
|
||||
}
|
29
GutenTag/test.html
Normal file
29
GutenTag/test.html
Normal file
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="test.css">
|
||||
<script src="test.js"></script>
|
||||
<title>Guessing game</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="center">WELCOME TO OUR<br>GUESSING GAME</h1>
|
||||
<div class="center">
|
||||
<button id="start" onclick="startGame()" class="biggerSize">Let's start!!!</button>
|
||||
</div>
|
||||
|
||||
<div id="gameId" class="center" style="visibility: hidden">
|
||||
<h3>I'm thinking about a number between 1 and 100...</h3>
|
||||
<p class="biggerSize">Your guess</p>
|
||||
<input id="guess" type="text" class="center biggerSize">
|
||||
<button id="guessBtn" onclick="gameFunc()" class="biggerSize">Guess</button>
|
||||
<h1 id="result"></h1>
|
||||
</div>
|
||||
|
||||
<div id="restart" class="center" style="visibility: hidden">
|
||||
<button onclick="restart()" class="biggerSize">Let's play again!</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
42
GutenTag/test.js
Normal file
42
GutenTag/test.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
var randomNum = Math.floor(Math.random() * 100) + 1;
|
||||
var guessCount = 0;
|
||||
|
||||
function startGame() {
|
||||
var gameDiv = document.getElementById("gameId");
|
||||
gameDiv.style.visibility = "visible";
|
||||
}
|
||||
|
||||
function gameFunc() {
|
||||
guessCount ++;
|
||||
|
||||
var startBtn = document.getElementById("start");
|
||||
var input = document.getElementById("guess");
|
||||
var result = document.getElementById("result");
|
||||
var restart = document.getElementById("restart");
|
||||
var playerGuess = input.value;
|
||||
var guessBtn = document.getElementById("guessBtn");
|
||||
|
||||
if (isNaN(playerGuess) ||
|
||||
!Number.isInteger(parseInt(playerGuess)) ||
|
||||
parseInt(playerGuess) <= 0 ||
|
||||
parseInt(playerGuess) > 100) {
|
||||
alert("Please enter an integer between 1 and 100");
|
||||
input.value = "";
|
||||
} else if (parseInt(playerGuess) == randomNum) {
|
||||
result.innerHTML = "You are right!!! " + randomNum + " is a correct guess. You made it right in " + guessCount + " guesses";
|
||||
startBtn.disabled = "true";
|
||||
guessBtn.disabled = "true";
|
||||
input.disabled = "true";
|
||||
restart.style.visibility = "visible";
|
||||
} else if (parseInt(playerGuess) > randomNum) {
|
||||
result.innerHTML = "It's lower";
|
||||
input.value = "";
|
||||
} else if (parseInt(playerGuess) < randomNum) {
|
||||
result.innerHTML = "It's higher";
|
||||
input.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
function restart() {
|
||||
window.location.reload();
|
||||
}
|
Loading…
Reference in a new issue