View Single Post
Old 03-31-2012, 12:10 PM   PM User | #1
HungryChapstick
New to the CF scene

 
Join Date: Feb 2012
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
HungryChapstick is an unknown quantity at this point
Number Guessing game

Hello!

So, here is my problem.

I have to write a number-guessing game that prompts the visitor to guess the right number in a maximum of 4 attempts. If the visitor guesses the target number within 4 tries, I want to write an alert that congratulates them as well as indicates the number of tries taken.

If they guess incorrectly, I want to prompt with "Try again."

And I finally want to keep track of each number they typed with a document.write.

I have something like this, but its just not working out:

Code:
<script type="text/javascript">

var count = "" ;

	if (count >=0 && count <=88) {		

			
for (i=1; i<=4; i++) {
	count = prompt("I'm thinking of a number between 0-88. Can you guess it?", "");
	document.write("Guess #" + i + ":" + count + "<br />"); 
	
}}
	else if (count>88){
		alert("Too high!")
		}
		else if (count=55){
			alert("Congratulations, you guessed it in " + i + " tries!)
			}
			else{
				alert ("Guess again!")
				}

</script>
Thank you for your time.

Last edited by HungryChapstick; 03-31-2012 at 01:13 PM..
HungryChapstick is offline   Reply With Quote