Welcome to the Treehouse Community
Looking to learn something new?
Why does he create an extra variable?
Why does he create the topNumber variable when you could just do like this?:
var userNumber = prompt("Write a number");
var result = Math.floor ( Math.random() * parseInt(userNumber) + 1 );
Is there a reason for that or does he just want to be super-clear?
Steven Parker216,148 Points
Breaking the process into steps at this point probably doesn't seem to make a big difference.
But as the lesson progresses, the formula is enhanced; and keeping the input and conversion operations separate from the calculation will make understanding the formula a lot less complicated.
I have done something similar. Rather than creating an extra variable, to make things simpler i have just added "parseInt" at the beginning when prompting for an input.
var topNunber = parseInt ( prompt ("Please provide a number.") );
Can this be one of the simpler way.