I am trying to make a number guessing game I have the basic part of it down but I am trying to manipulate it so that it initially stores a random number and from there the player keeps guessing till they get it right. If I should continue with the switch statement let me know or should i go back to the if/else statement.
<!DOCTYPE html>
<html>
<style>
</style>
<body>
<h1 id="prompt">Can you guess the number I am thinking of?</h1>
<h2 id="prompt2"></h2>
<input id="guess" type="text" value=""> <!--Box for the input-->
<input type="button" value="guess" onclick="numberGuess();"><!--Button
that exacutes the code-->
</body>
<script>
var randomNumber =Math.floor((Math.random()*10)+1)
function numberGuess() {
var number= randomNumber;
var yourGuess=document.getElementById('guess');
switch (guesspart) {
case (yourGuess==randomNumber) :
console.log('Correct');
break;
case (yourGuess!=randomNumber):
console.log('Correct');
break;
default:
console.log(number);
}};
/*if (yourGuess==randomNumber){
document.getElementById('prompt').innerHTML ='You have guessed
Correctly';
}
else (yourGuess!=randomNumber)
document.getElementById('prompt').innerHTML='Sorry the number was
'+randomNumber;
};*/
</script>
</html>
Aucun commentaire:
Enregistrer un commentaire