<body>
<input id ="guessNumber" type="text">
<button id="button" onclick="check()">click here</button>
<script language="javascript" type="text/javascript">
var randomNumber = Math.floor((Math.random()*6));
var guessNumber = document.getElementById("guessNumber").value;
function check() {
if(guessNumber==randomNumber){
alert("you are correct");
}
else {
alert("you are wrong");
}
}
</script>
</body>
I want to write a small number game program where I put in a number and if the Math.random method value are equal it should alert "TRUE" but its just alerting "FALSE"("it is wrong" my alert code) all the time.Give me an explanation why that is happening not just the answer and why is guessNumber variable a string ?
Aucun commentaire:
Enregistrer un commentaire