I run this solution and this worked! Is there any expert that tell me about this is a right way or not, please.
Here is the Link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/generate-random-fractions-with-javascript
function randomFraction() {
// Only change code below this line
if (Math.random() > 0) {
return Math.random() * 0.5;
} else {
return 0;
}
// Only change code above this line
}
var ans = randomFraction(10);
console.log(ans);
hbar1st
September 13, 2022, 10:47am
2
Please post a link to the challenge you were attempting.
hbar1st
September 13, 2022, 11:03am
4
Thanks for posting.
I think your code is more than was needed.
Try rewriting it into one line only.
here is a hint to how it should start:
return Math.random(…
please read challenge again see what is returned by Math.random()
0 <= Math.random() < 1
so if you multiply it by 0.5 it will always be a fraction.
system
Closed
March 15, 2023, 5:08am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.