Tell us what’s happening:
Hi, I passed this challenge but don’t understand what I wrote is enough? and its is not clear for me. can some explain me? thanks
Your code so far
function randomFraction() {
// Only change code below this line
return Math.random();
return 0;
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5
.
Challenge: Generate Random Fractions with JavaScript
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Hello SARA1985 ,
Your code has two returns statements which is incorrect. You should remove “return 0;” and try again.
1 Like
You passed the challenge because the function exited after the first return statement.
You are supposed to just return a random number with Math.random
1 Like
Hi Sara1985,
I will try to explain what I understood.
Math.random() is a function which will generate decimal numbers greater or equal to 0 but less than 1 (like - 0.098766, 0.134566, etc).
The challenge here was for the randomFraction function to return a decimal which Math.random() does. Hence, what you wrote was enough.
Hope this helps.
1 Like
There is a possibility (small one) that Math.random would return 0.
Try to add something to Math.random to avoid that Math.random + 1 for example .
Your solution never reaches the second return statement because the function terminates on the first one.
1 Like
@ClemHlrdt @samolex @manjupillai16 @GeorgeCrisan
Thanks guysss for your response and explanation. I understood that.