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 Basics (Retired) Creating Reusable Code with Functions Random Number Challenge

Stephen Gough Jr
Stephen Gough Jr
4,187 Points

Question about this challenge's code...

Granted, this took me CONSIDERATELY longer to comprehend than the previous HTML and CSS courses, but I believe I finally sort of have it down somewhat. I don't know if this is too long or too unorthodox, but my code is:

var lower = function lowEquation (a) {

return (Math.floor(Math.random() * (6 - 1 + a))); }

var higher = function highEquation (b) {

return (Math.floor(Math.random() * (6 - 1 + b))); } alert ((lower(10).toString()) + " and " + higher(40).toString());

In my browser, I get a set of two different numbers, and I believe that's what the challenge asked of, unless I misunderstood. I'm not going to look at the next video yet until I discuss it because I am proud I was even able to do this.

Stephen Gough Jr
Stephen Gough Jr
4,187 Points

So after looking at other peoples' codes, seems like I did mines horribly wrong haha... pride effectively deflated.

1 Answer

Steven Parker
Steven Parker
231,275 Points

I think you may have misinterpreted the objectives. Your task is to create only one function, but it will take two argument values. By using those two values with the formula provided, you would then create a random number that lies between (inclusively) those two argument values. Then you return that value.