Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Improving the Random Number Guessing Game

Anthony C
Anthony C
4,636 Points

prompt is not popping up

I am following the code from the video but my prompts are not working. Not sure why.

var correctGuess = false;
var randomNumber = Math.floor(Math.random() * 6) + 1;
var guess = prompt('I am thinking of a number between 1 and 6. What is it?');
if (parseInt(guess) === randomNumber ) {
  correctGuess = true;
} else if ( parseInt(guess) < randomNumber ) {
  var guessMore = prompt('Try again. The number I am thinking of is more than ' + guess);
  if (parseInt(guessMore) === randomNumber) {
      correctGuess = true;
  }
} else if ( parseInt(guess) > randomNumer ) {
  var guessLess = prompt('Try again. The number I am thinking of is less than ' + guess);
  if (parseInt(guessLess) === randomNumber) {
      correctGuess = true;
}
if ( correctGuess ) {
    document.write('<p>You guessed the number!</p>');
} else {
    document.write('<p>Sorry. The number was ' + randomNumber + '.</p>');
}

MODERATOR EDIT: Added Markdown to the code snippet so that it is readable in the community. Please refer to the Markdown Cheatsheet when posting code snippets for the proper way to do so in the Community Forum.

Matthew Smith
Matthew Smith
10,945 Points

You didn't close your conditional statement on line 11 -- there's a " { " but not a closer "}".

Here's what I did and made it work!

} else if ( parseInt(guess) > randomNumer ) {
  var guessLess = prompt('Try again. The number I am thinking of is less than ' + guess);
}if (parseInt(guessLess) === randomNumber) {
      correctGuess = true;
}
Anthony C
Anthony C
4,636 Points

Thank you for the help!

I'm having a similar problem.

var correctGuess = false; var randomNumber = Math.floor(Math.random() * 6 ) + 1; var guess = prompt('I am thinking of a number between 1 and 6. What is it?'); if (parseInt(guess) === randomNumber ) { correctGuess = true; } else if (parseInt(guess) < randomNumber ) { var guessMore = prompt ('Try again. The number I am thinking of is more than ' + guess); if (parseInt(guessMore) === randomNumber { correctGuess=true; } } else if (parseInt(guess) > randomNumber ) { var guessLess = prompt('Try again. The number I am thinking of is less than ' + guess); if (parseInt(guessLess) === randomNumber { correctGuess=true; } if ( correctGuess ) { document.write('<p>You guessed the number!</p>'); } else { document.write('<p>Sorry. The number was ' + randomNumber +'.</p>'); }