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 Build a Random Number Guessing Game

Carleen Hall
seal-mask
.a{fill-rule:evenodd;}techdegree
Carleen Hall
Front End Web Development Techdegree Student 3,158 Points

Can someone tell me what's wrong with my code? It's just not working.

var randomNumber = Math.floor(Math.random() * 6) + 1;
var guess = prompt( "I am thinking of a number between 1 and 6. What number am I thinking of?");
if (parseInt(guess) === randomNumber) {
  document.write("<p> You guessed it!</p>");
} 
 else {
  document.write("<p>The correct number was" + randomNumber "</p>"); 
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! In short: you forgot a + sign. This is creating a syntax error in your code. If I rewrite your last document.write statement, it works! Take a look:

document.write("<p>The correct number was " + randomNumber + "</p>"); 

Note that I also included an extra space in the string. Otherwise the output looks like this: "The correct number was2". Hope this helps! :sparkles:

nathaniel marquez
seal-mask
.a{fill-rule:evenodd;}techdegree
nathaniel marquez
Full Stack JavaScript Techdegree Student 2,145 Points

I was using JShint.com to test my code and it kept throwing errors for line 7.

Expected ')' and instead saw ' '. 7 Missing semicolon. 7 Expected an identifier and instead saw ')'. 7 Expected an assignment or function call and instead saw an expression.

and it was in fact the second addition symbol that I was missing ... I REALLY HATE JS, and yet its fascinating enough to keep trying.