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)
![Zydrunas Likas](https://secure.gravatar.com/avatar/dbff4ccd8d0e9e979cb2e5f774f858ad?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zydrunas Likas
3,952 PointsMy solution for Function Challenge Solution any advice welcome
alert ("Ready to find any random number between your any numbers??");
const param2 = +prompt("Please provide smalest Number?");
const param1 = +prompt("Now its time for bigger Number?");
const randomNumber = (param1, param2) => {
const randomNumberbetween = Math.floor(Math.random() * (param1 - param2 + 1 )) + param2;
if (isNaN(param1) || isNaN(param2)) {
return alert("You choose not a numbers!!!");
} else if ( param1 <= param2) {
return alert("You choose not correct Numbers!!!")
} else {
return alert(`Your Random Number Is ${randomNumberbetween} between ${param1} and ${param2}!!!`);
}
}
randomNumber(param1, param2);
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsSince you're doing validity checking on the arguments, you might want to perform the calculation only after the arguments are determined valid.
Also, using the unary "+" to convert a string to a number can cause unexpected results. For example, if the user submits a blank line, it will be converted into 0; but you might prefer it to be considered a "not a number" response, which is what you would get by converting with parseInt()
.
But in general, good job!