Basic JavaScript: Generate Random Fractions with JavaScript

Hello, everyone! I’ve just started learning Javascript with this site, and I passed this test.
but I’ve no idea how did it work. Could anyone explain for me why it worked?

function randomFraction() {

  // Only change code below this line

if(Math.random()){

  return Math.random();

}

  // Only change code above this line

}

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 @enda11!

Every time you call the function it will generate a random number with a decimal that could be anything from 0 to not quite up to 1. So the instructions were to change it from returning 0 every single time to a random number .

For future challenges it would help out the community if you included the link to the lesson you are working on. You can do this with the ask for help button in the challenge too.

I am also going to link mdn docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random