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 trialArmin Kadic
16,242 PointsWhy is my one number method working but the two numbers not?
Hi!
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.
1 Answer
Steven Parker
231,268 PointsYou didn't use "parseInt" on the last term, so it's being handled as a string instead of a number.
Armin Kadic
16,242 PointsArmin Kadic
16,242 PointsThank you my saviour!