The current issue i am having is probably a simple one for most but i seem to have issues when using functions. My goal is to have the game prompt the person for a number between 1 and 100 if the person put's in an invalid number it will alert them and ask for a new number. If the person put a number over the random number it will inform them they are to high and allow them to try again and the same if the number is to low.
<!doctype html>
<html lang="en">
<head>
<title>Guess game</title>
<meta charset="utf-8">
</head>
<body>
<script>
var guess;
var randomNum = Math.floor(Math.random() * (100 - 1 + 1)) + 1;
var answer = false;
while(answer == false){
guess = prompt("Take a stab in the dark(1 to 100)");
wrongGuess(guess);
checkGuess(guess);
function wrongGuess(guess){
if(guess == null){
alert("Bye");
prompt.close;
}
else if(guess < 0 || guess > 100 || guess == "" || guess == " "){
alert("Write a valid number");
}
}
function checkGuess(guess){
if (guess > randomNum){
alert("Number is to High");
if (guess == randomNum){
answer = true;
alert("Grats Mate you hit the nail on the head");
}
else{
alert("That number is to low");
}
}
}
}
</script>
</head>
</html>
I have it were it will ask for the numbers but it does not follow the funtion rules for checking to see if the number is over the random number it will alert you if the number is outside of the range though.
Aucun commentaire:
Enregistrer un commentaire