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 Numbers The Math Object Random Number Challenge – Solution

JavaScript Numbers..

https://w.trhou.se/oyyvzhh1la

Really i need help with creating a Integer number. I feel ParseInt should do this but isn't. I know i've gone wrong somewhere at line 8 i think. Although i do think line 11 is right haha.

Thanks for any help guys.

6 Answers

Steven Parker
Steven Parker
231,268 Points

Here's some hints:

  • Math.random() doesn't require an argument, and any given will be ignored
  • Math.random() generates a non-integer value between 0 and 1
  • a common way to get random integers is to multiply by a range and then use Math.floor

What is an argument and what is a range?

Steven Parker
Steven Parker
231,268 Points

An argument is the data passed to a function, examples:

let dollars = Math.floor(price); // "price" is an argument
let randFloat = Math.random();   // this function doesn't take any argument

And a "range" is a span of numbers (how many numbers). So if you wanted a random integer from 0 to 5, the "range" would be 6 (6 possible numbers: 0,1,2,3,4,5).

That is very useful! I will print that out, Thank you.

It's mid August now and i still can't get it. I can't ever seem to remember it all? If its in the exam can i research it online (serious question?)

So how do i go about getting ready for exam should the time come? (I have it in mind to learn as much as possible first). I haven't seen any information on this, that's why i'm not sure.

Steven Parker
Steven Parker
231,268 Points

Where would you getting this "exam"?

I don't know. I'm finding it hard to get information

Steven Parker
Steven Parker
231,268 Points

Only techdegree students have an "exam", you won't have anything like that. For the rest of us, everything is self-paced and open-book.

If you're going to have an exam somewhere else (employer, certification authority, etc) the source may provide prep tips, or there may be 3rd party prep info providers.