Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Build a Random Number Guessing Game

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:

Thanks Jennifer. It worked.

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.