Code : Tout sélectionner
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Création d'un jeu</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<div id="wrapper">
<form method="post" action="" name="submitForm" onsubmit="return validerLeFormulaire()">
<table>
<thead>
<tr>
<th>Création d'un jeu</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="number" id="number" placeholder="nombre"></td>
</tr>
</tbody>
<tfoot>
<tr>
<th><input type="submit" value="Valider" id="submit"></th>
</tr>
</tfoot>
</table>
</form>
</div>
</body>
</html>
Code : Tout sélectionner
function validerLeFormulaire() {
var number = document.forms["submitForm"]["number"].value;
if(isNaN(number)) {
alert("Vous devez indiquer un nombre !");
}
if else(number < randon) {
alert("Le nombre indiqué est trop petit");
}
if else(number > random) {
alert("Le nombre indiqué est trop grand");
}
if else(number == random) {
alert("Vous avez gagné !");
}
var min = 1;
var max = 100;
var random = Math.floor(Math.random() * (max - min)) + min;
alert(random);
}