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 trialmohamedhalabi
1,968 Pointscode output is not as expected -_-
var lower = parseInt (prompt ('Enter Min Number') ) ;
var upper = parseInt (prompt ('Enter Max Number') ) ;
function getRandomNumber (lower , upper) { if (upper > lower){
var randomNumber = Math.floor(Math.random() * (upper - lower + 1)) + lower;
return randomNumber;
}else {
var randomNumber = Math.floor(Math.random() * (lower - upper + 1)) + upper;
return randomNumber ; }
}
alert(getRandomNumber);
can someone please let me know why is my output he actual function details themselves ?
2 Answers
Dan Weru
47,649 PointsHey, you're doing great. You just need to tweak your code a little. You need to add the opening and closing parenthesis () after getRandomNumber. Doing so makes the function to execute.
Instead of this
alert(getRandomNumber);
Write this
alert(getRandomNumber());
Or write
var result = getRandomNumber();
alert(result);
Péter Topos
6,153 Pointsyou should call the function with parentheses after the function's name in the alert like this: alert(getRandomNumber()) ;
mohamedhalabi
1,968 Pointsthanks
mohamedhalabi
1,968 Pointsmohamedhalabi
1,968 Pointsseems like my console is always displaying NAN as a result for some reason !
Bret Lynn
7,037 PointsBret Lynn
7,037 PointsHere's how I did mine...seems to work. I suppose I cheated a little....I used MDN to find help.
function getRandomArbitrary (min, max) { return Math.floor (Math.random() * (max - min) + min); }
alert (getRandomArbitrary(20, 100));