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

JavaScript JavaScript Functions Arrow Functions Testing for Number Arguments

Zydrunas Likas
Zydrunas Likas
3,952 Points

My 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
Steven Parker
229,005 Points

Since 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!   :+1: