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 trialGary Calhoun
10,317 PointsIs this correct?
Hi was just trying to see if I did this correctly.
function getRandomNumber(upper, lower){
var randomNumber = Math.floor(Math.random() * (6 - upper + lower)) + 1;
return randomNumber;
}
document.write(getRandomNumber(10, 100));
3 Answers
Joel Smith
14,779 Pointsno, but close. it would be easier to trim that up a bit.
try this:
var getRandomNumber = function(upper, lower){
return Math.floor(Math.random() * (6 - upper + lower )) + 1;
};
document.write(getRandomNumber(10, 100));
Gary Calhoun
10,317 PointsThanks Joel!
Joel Smith
14,779 Pointswhat you had wouldn't have worked, because you defined your function as a variable like so:
var getRandomNumber(upper, lower) = ......
but you cannot place arguments into the definition of a variable. If you had defined it like so:
var getRandomNumber = function(upper, lower) {....}...
that would have been correct.
You were sooo close! just keep an eye on the little things like that and you'll go very far. :)
Gary Calhoun
10,317 PointsAhh I see what you mean, thanks again either way I just gained a level:)