Welcome to the Treehouse Community
Looking to learn something new?
wei du2,569 Points
is the '()'position important in this question?
var userNum = parseInt(prompt('What is your number?')); var userNum_1 = parseInt(prompt('what\'s your least favor number?')); var genNum = Math.floor(Math.random() * (userNum - userNum_1 + 1)) + userNum_1; alert(genNum);
var userNum = parseInt(prompt('What is your number?')); var userNum_1 = parseInt(prompt('what\'s your leat favor number?')); var genNum = Math.floor(Math.random() * (userNum - userNum_1 + 1)+ userNum_1); alert(genNum);
please note the position of the parentheses on line 4. I have tried both ways, and both worked, but just wondering if one is better than other? Or I just got lucky on this one?
Milan Pankhania3,734 Points
So it looks like the parenthesis difference is in the Math.floor function you're talking about? In this instance the test may have passed as it might not have been looking for the correct answer value, I'm not sure, but yes where you close the parenthesis will have an effect on the result. Basically when you put anything inside the parenthesis of a method, that means that you want to do something with the code inside of it, anything outside of the parenthesis doesn't get affected.
Hope that helps?
It seems to me what you are essentially asking is does:
Math.floor(userNum_1) = userNum_1 ?
Since userNum_1 is a positive integer the answer is yes so the position of the parentheses are not important in this case.