Generate Random Fractions with JavaScript Question

why does return Math.random(); work if this can in fact return 0 ?

function randomFraction() {

// Only change code below this line

return Math.random();

// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Generate Random Fractions with JavaScript

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

HI @vincentlomeli !

Welcome to the forum!

Math.random can return 0 but it can also return random numbers like these

The goal of this exercise is to generate a new random number every time the function is called.

If you just leave it at 0 then it will only return 0 every time.

Thank you. I was confused because the exercise ask to generate a random number “not 0” and the solution can in fact return 0. Again, thank you for taking the time to help.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.