Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Functions Arrow Functions Testing for Number Arguments

nasser mohammed
nasser mohammed
12,193 Points

Testing for Number Arguments Pass a string argument

Hi. When I pass a string argument like '10', the function not work well, either when I did the testing.

const getRandom = (lower, upper) => { if (isNaN(lower) || isNaN(upper)) { document.querySelector('main').innerHTML = <h2>The 2 values should be numbers</h2>; } else { const random = Math.floor(Math.random() * (upper - lower + 1)) + lower; const main = document.querySelector('main').innerHTML = <h2>${random} is a random number between ${lower} and ${upper}<h2>; return main; } };


the result is: 310 is a random number between 10 and 40