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 trialMarc Amil
Courses Plus Student 928 PointsWHY IS MY CODE NOT WORKING?
// function function getRandomNumber( lower, upper){ if ( isNaN(lower)||isNaN(upper) ){ throw new Error('error message'); } else return Math.floor(Math.random() * (upper - lower + 1)) + lower; }
// question var upper = prompt("Put in an upper number"); var lower = prompt("Put in a lower number"); console.log(getRandomNumber(lower, upper));
I want the user to be able to input numbers, and the error message works and a value pops up but it never fits on to the range and boundary that the user inputs in.
1 Answer
Razvan Sarbu
9,919 PointsBecause the data you got from the prompt function is actually a string. You need to parse both "numbers" to int, like this: upper = parseInt(upper); lower = parseInt(lower);
Then, you should call the function.