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

Benjamin Miller
Benjamin Miller
4,344 Points

how the heck?!!!

So I followed along and there was a browser error. WHAT?

my current code: 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 ) { document.write('<p>You guessed the number!</p>'); } else { document.write('<p>Sorry. The number was ' + randomNumber + '</p>); }

Help!

3 Answers

Steven Parker
Steven Parker
230,248 Points

:point_right: It looks like your problem is a missing closing quote on your last string. You probably meant:

document.write('<p>Sorry. The number was ' + randomNumber + '</p>');  // <- quote added at end
Marco Boretto
Marco Boretto
29,821 Points

Math.floor(Math.random() * 6 ) + 1 always generates 1 if you want to generate a random number between 1 and 6 try this :

Math.floor(Math.random()*6+1) 
Steven Parker
Steven Parker
230,248 Points

Actually, both of those do exacty the same thing - it makes no difference if you add a whole number inside or outside the floor function.

Marco Boretto
Marco Boretto
29,821 Points

i think you missed an ' at the end of else { document.write('<p>Sorry. The number was ' + randomNumber + '</p>); }