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!
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
Armin Kadic16,242 Points
Why is my one number method working but the two numbers not?
My method is a bit different because I tried to make it shorter with less variables. So as the title says, the method for one number is working while the second one for two numbers is not even tho I use the similar method?
One random number:
var topNumber = prompt("Type a number to get a random to it.");
alert(Math.floor( Math.random() * (parseInt(topNumber)))+1);
Two random number:
var topNumber = prompt("Type a top number.");
var bottomNumber = prompt("Type a bottom number.");
alert(Math.floor(Math.random() * (parseInt(topNumber) - parseInt(bottomNumber) +1 )) + bottomNumber);
Thanks in advance.
Steven Parker228,077 Points
You didn't use "parseInt" on the last term, so it's being handled as a string instead of a number.