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 trialM W
3,446 PointsPrompt box will not appear unless I delete the next lines of code!
I am doing the random number challenge which seems fine except I cannot get the prompt dialogue box to appear. If I remove the code after the prompt line it works...I thought the code was run in sequence so even if my code after the prompt line is wrong, then the prompt box wold still appear then I would get an error. Any thoughts please? Thank you :)
P.S. I know the remaining code needs finishing - I'm just stuck with the Prompt issue....:)
var input = prompt("Please enter any number and I will give you a random number from 1 up to the number you give me!");
var finalUserNumber = parseInt(input);
var result = Math.floor(Math.random() * finalUserNumber) + 1);
alert('Your random number is ' + result);
4 Answers
Steven Parker
231,269 PointsYou have an extra closing parenthesis on this line:
var result = Math.floor(Math.random() * finalUserNumber) + 1);
You can either remove the last one (my recommendation), remove the one before the "+", or add another open parentheses before or after "Math.floor".
Syntax errors are detected before the script begins running, and prevent execution.
Konstantin Kovar
16,003 PointsThere is an access ')' on the third line. This should fix the problem. The line should be:
var result = Math.floor(Math.random() * finalUserNumber + 1);
I'm sorry I don't really know a lot about what's going on under the hood, so I can't tell you why an error on line 3 would prevent line 1 from working, but it's possible (apparently).
Erik Nuber
20,629 Pointshave you tried testing in the console. I would try finding out if there is an error and, entering input to see what it gives back. It looks correct here so you may want to make sure your html file has the javaScript file connected properly.
That or make a simple test and put
alert('hello');
just to see if anything is actually running.
M W
3,446 Pointsseems it was the extra parenthesis later on in the code :)
M W
3,446 PointsThanks everyone for crazily speedy responses. I had no idea that syntax errors throughout program were checked before executing the code! I must have missed that somewhere. Thanks again :)