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
adrien kovanic
5,727 Pointswould this answer also work?
Hi, I am doing the JavaScript JavaScript Basics Creating Reusable Code with Functions Random Number Challenge, Part II would this solution also be correct? ( I am not checking if the arguments are number I know)
thanks a lot :)
function calculus (lowerNumber, higherNumber){ var result = Math.floor(Math.random() * (higherNumber)) + 1;
if (result > lowerNumber){ alert("the number is" + result); } else { var minresult = result + lowerNumber; alert("the number is" + minresult); } } console.log(calculus(100 , 200));
3 Answers
Robert Stefanic
35,170 PointsYeah it works. It's a little bit of a round-about way to get a random number between 100 and 200.
It would generally just be easier to put them in one argument though.
Also, as quick note, by the way you're calling your function in a console.log statement, it's better to have it return something. Right now if you were to run your function, it would display everything as an alert box, rather than having it return a value in your console.log call. So you'll get an undefined in your console, and it's not really doing anything.
So you could either just call your function:
calculus(100, 200);
Or just remove the alerts, and have them return values so that your console.log call to your function returns a value.
Best of luck. :)
rydavim
18,814 PointsPlease see Steven Parker 's answer over here.
Steven Parker
243,658 PointsFor your convenience, I'll repeat my answer to your previous post of this same question:
This code will produce numbers outside the range.
Try calling it with a narrow range of larger numbers, like: calculus(950, 999) a few times and see. Plus even if it was modified to constrain the answers to the range, the distribution would be uneven.