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 trialMarko Delgadillo
4,524 PointsWhy is it necessary for the first challenge to have parseInt?
My code is as follows and works!
var select=prompt("Select a number MORE than the number 1"); var random= Math.floor( Math.random() * select) +1; var message= random + " is a number between 1 and " + select; document.write(message);
1 Answer
Joe Beltramo
Courses Plus Student 22,191 PointsIf you are asking why you should use parseInt()
around the variable assigned to the prompt
response (in your case select), it is because the prompt
always returns the value as a string. Anytime you are working with numerical values, you will want them to be actual numerical values as to properly throw or not throw an error when using them.
Especially with javascript, it is important to know that
"1" !== 1