JavaScript Decimal

how can I change my code to return a decimal value?

Your code so far


function randomFraction() {

// Only change code below this line

return 0;var num = Math.random();
if (Math.random(num) == 0) {
return num;
}
// Only change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36.

Challenge: Generate Random Fractions with JavaScript

Link to the challenge:

Right now you have a return statement at the top of your function. That means that your function will always return 0 and that no code after that return will execute.

1 Like

still doesn’t work even after removing the return statement.

if (Math.random(num) == 0) {
return num;
}

Can you explain the logic here? What are you trying to achieve?