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

Running into an issue with JavaScript alerts

I keep mirroring exactly what Dave McFarland is coding in the JavaScript Basics Random Number Generator demonstration, but for some reason I'm not getting prompts popping up like his code is. This has happened a few times with different challenges, and it eventually resolves, but I haven't found any specific action that I know is the one helping. Here is the code I am entering into the js file, and I checked the html file to make sure it's sourcing the js file correctly, and it is. Can anyone help?

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>Ding ding ding! You got it</p>'); 
} else {
    document.write('<p>Sorry.  The number was ' + randomNumber + '</p>');
}
Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,741 Points

Question updated with code formatting. Check out the Markdown Cheatsheet for syntax examples.

1 Answer

Hi Emily, your code is fine, the only issue is the punctuation marks within which you enclosed your question. I don't know what they are but they aren't the normal single(' ') or double quote marks(" "). Just change that and you're good to go :)

Gosh, that's so weird. I'm using the normal key that has the apostrophe and quote mark. I don't know what could possibly be happening, but I'll give it a try. Thanks!