function randomFraction() {
// Only change code below this line.
let result = 0;
// Math.random() can generate 0. We don't want to return a 0,
// so keep generating random numbers until we get one that isn't 0
while (result === 0) {
result = Math.random();
}
return result;
// Only change code above this line.
}
function randomFraction() {
// Only change code below this line.
return 4; // chosen by fair dice roll.
// guaranteed to be random.
// Only change code above this line.
}
Is there anything inherently wrong with what I did?
function randomFraction() {
// Only change code below this line.
var x , a , b;
x= 0;
a = 0;
b = 0;
x += Math.random();
a += Math.random();
b = x/a;
return b;
This challenge is presenting me with the math.Random() function. math.Random() returns a number between 0 (inclusive) and 1 (exclusive). The challenge wants me to create a function using math.Random() that makes the 0 exclusive.
Math.random() function returns decimal values.
function randomFraction() {
// Only change code below this line
var aa = Math.random();
console.log(aa);
return aa;
// you can see output value within your challenge window, it will clarify the usage of function in detail when you check its output.
// Only change code above this line.
}
Okay, so it pretty much still returns a decimal value in the console. Now is that because aa stores to what Math.random() is doing, which is to handle numeric values(more than 0 but less than 1). Am I correct in that assumption?
Math.random(); function that generates a random decimal number 0(inclusive). So it is not required to check using if condition because 0 is a integer number.
You can try reversing condition for better clarification
// Only change code below this line.
var num = Math.random();
if (Math.random(num) == 0) {
return num;
}
So extra code not required here.