Hi, Iīm a computerīs programming student. Iīm glad about finding this site. Iīm thrying to build a game wit the following conditions:
Computer should pick a random number between 1 and 100, inclusive.
Player inputs their guess
Program should respond "too high", "too low" or "correct"
If the guess is "too high" or "too low" the game should continue (player makes next guess.)
If the guess is correct, the game should end, and the player should be told how many guesses it took to win.
Include a "new game" button that allows a new game to begin if the user clicks it. (You should pick a new random number, and reset the number of guesses.)
I have the following code, but it is not working and I donīt know why. This code for an action script 3.0 program. Iīm also attaching a list of mistakes that I donīt know how to solve since Iīm very new in this field. I hope somebody can help me in fixing this.
CODE
var msg:String = "Enter a number between 1 and 100";
var theNumber:Number = Math.floor(Math.random()*100+1);
var totalGuesses:Number = 0;
var theGuess:Number;
display.text = msg;
guesses.text = totalGuesses = 0;
/*Create a function to check the guessed number against the random numberThe function will run each time the user clicks on the Enter button
*/
rollbtn.onRelease = function() {
/* Extract the guess from the input box */
theGuess = Number(guess.text);
/* Add 1 to the total number of guesses */
totalGuesses++;
/* Display the total number of guesses */
guesses.text = totalGuesses;
/*
Check to to see if the guess equals the random number
IF it does THEN
pick a new random number
reset the total number of guesses to zero
clear the input box
prompt the player to play again
ELSE
Provide the player with feedback
*/
if (theGuess == theNumber) {
display.text = "You Got It! \n Play Again";
theNumber = Math.floor(Math.random()*100+1);
totalGuesses = 0;
guess.text = "";
} else if (theGuess > theNumber) {
display.text = "Too High";
} else if (theGuess < theNumber) {
display.text = "Too Low";
} else {
display.text = "Not a Number\nTry again";
}
};
Thanks for your help
** Edit **