# Guessing Game Problems

Page 1 of 1

## 5 Replies - 706 Views - Last Post: 17 March 2012 - 04:38 PM

### #1 gamergrl22

Reputation: 0
• Posts: 3
• Joined: 17-March 12

# Guessing Game Problems

Posted 17 March 2012 - 08:58 AM

This it my first (and only) programming class I have so be gentle! I have to make a guessing game where the user chooses the max number to guess between 1 and that number, and then they guess until they get it while stating too high or too low. It works up until the random number part and giving the "too high", "too low" and "you win" prompts. Firebug said something was wrong with the == for the if (guess == random_number) part.

Thanks!

}

var user_max = ask("Welcome! What number would you like to be the max?");

alert("The number you have chosen is " + user_max);

function random (random_number) {

var com_answer = prompt(random_number, 1 + Math.floor(Math.random() * max))

}

guess = prompt("Guess a number between 1 and " + user_max + "?");{

if (guess == random_number) {
}
else if (guess > random_number) {
}
else if (guess < random_number) {
}
}

Is This A Good Question/Topic? 0

## Replies To: Guessing Game Problems

### #2 GregBrannon

• D.I.C Lover

Reputation: 2250
• Posts: 5,340
• Joined: 10-September 10

## Re: Guessing Game Problems

Posted 17 March 2012 - 09:26 AM

This is a Java forum. What you've posted is not Java.

### #3 Dogstopper

Reputation: 2956
• Posts: 11,220
• Joined: 15-July 08

## Re: Guessing Game Problems

Posted 17 March 2012 - 09:48 AM

As I always say, Java != Javascript

Moved to the Javascript forum.

• Saucy!

Reputation: 6237
• Posts: 24,002
• Joined: 23-August 08

## Re: Guessing Game Problems

Posted 17 March 2012 - 01:27 PM

guess = prompt("Guess a number between 1 and " + user_max + "?");{

Why is there a { after that line (and the extra closing } at the end)?

guess = prompt("Guess a number between 1 and " + user_max + "?");{

if (guess == random_number) {
}
else if (guess > random_number) {
}
else if (guess < random_number) {
}

Where did the variable random_number come from? Did you perhaps forget to call a function?

### #5 gamergrl22

Reputation: 0
• Posts: 3
• Joined: 17-March 12

## Re: Guessing Game Problems

Posted 17 March 2012 - 04:01 PM

Sorry I didn't post this in the right one. Newbie!

As for the {/}'s firebug said it was wrong not to, well at least at the end anyways. It still says there is an error with the equal to statement. I screen shot it.

Sorry and the var random_number comes from the function above it that makes the random number for the game. I'm not sure if I'm setting it up right or not. Thanks!

### #6 gamergrl22

Reputation: 0
• Posts: 3
• Joined: 17-March 12

## Re: Guessing Game Problems

Posted 17 March 2012 - 04:38 PM

My teacher e-mailed me and sort of explained why it won't work. So, I've adjusted the code. I don't know if it was for the better, but here's hoping. It still doesn't work though.

}

var user_max = ask("Welcome! What number would you like to be the max?");

alert("Guess a number between 1 and " + user_max + "?");

function guessNumber(userGuess) {

var rightNumber = (1 + Math.floor(Math.random() * max));
return rightNumber

if (userGuess == rightNumber) {
alert("You've got it! You win! ^_^/>");
}
else if (userGuess > rightNumber) {
alert("You are too high. Guess again.");
}
else if (userGuess < rightNumber) {
alert("You are too low. Guess again.");
}
}