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 trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Yoan Halevy](https://secure.gravatar.com/avatar/2ab56a4bcbd50db7041c1e387dc354be?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Yoan Halevy
Full Stack JavaScript Techdegree Student 2,964 PointsThe code I have gives me back a value of "undefined". Can someone tell me why?
const randomNumber = (lower, upper) => {
Math.floor(Math.random() * (upper - lower + 1)) + lower;
if (isNaN(lower) || isNaN(upper)) {
throw Error ("You must select only numbers");
}
}
// Call the function and pass it different values
console.log(randomNumber(1,5));
console.log(`${randomNumber(5,100)} is a random number between 5 and 100`);
console.log(randomNumber("six",987324));
1 Answer
![Joseph Yhu](https://uploads.teamtreehouse.com/production/profile-photos/10742228/micro_121009504_105928134617925_5772733173913238661_n.jpg)
Joseph Yhu
PHP Development Techdegree Graduate 48,637 PointsYou have to return the random number, like this:
const randomNumber = (lower, upper) => {
if (isNaN(lower) || isNaN(upper)) {
throw Error ("You must select only numbers");
}
return Math.floor(Math.random() * (upper - lower + 1)) + lower;
}