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
203,223 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
203,223 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
203,223 Points

Where would you getting this "exam"?

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

Steven Parker
Steven Parker
203,223 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.