Welcome to the Treehouse Community
Looking to learn something new?
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.)