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 trialmoustafa ahmed
1,215 Pointsi forgot to add parseINT but i couldnt notice any wrong running my app
var userIput = prompt( "kindly add a number"); var randomNumber = Math.floor(Math.random() * userIput) +1; alert(randomNumber);
1 Answer
Tsenko Aleksiev
3,819 PointsTry adding 5x ( or any oder char after the number ) to the prompt box - you will get a NaN as a result. The type of the object from the prompt is allways a string but the Math methods floor and random do the conversion of the types. Try using Object.prototype.toString.call(the var name); If you try this on userIput before using the math methods you will see that the result be a string. Try the same thing but instead only the var name write this Math.floor(userIput) and you will get the result - number. For the sace of your program it works but don't do it in a real program ;)