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
Teacher Russell16,873 Points
I'm going to have to sleep on this one for a day, I guess. I don't see why it was necessary to use parseInt. I thought that was Math.floor's job. I suppose I didn't fully understand the instructions. Part 2 of the assignment will DEFINITELY have to wait until I understand why Dave did what he did in part 1. Here's my silly attempt before watching the solution.
var userNumber = prompt('Enter a number from 1 to 10') var randNum = Math.floor(Math.random() * userNumber) + 1; document.write(randNum);
The function parseInt converts the input string assigned to userNumber to an integer, whereas Math.floor rounds down (may also be called truncates) the decimal number to the nearest integer. Thus parseInt is explicitly converting from string type to integer type and Math.floor is converting from a float type to an integer type. (There should also be a semicolon to separate the two var statements.) (If Math.floor is given an integer, it will simply return the same integer.)