Basic Javascript - Generate Random Fractions with JavaScript

Tell us what’s happening:

why am I not seeing a random number? I also copied and pasted the code into repl.it and I’m getting an undefined message?

Your code so far


function randomFraction() {

  // Only change code below this line.
var result = 0;
while (result === 0){

result = Math.random();
}
  return result;

  // Only change code above this line.
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/generate-random-fractions-with-javascript

It works fine, in repl.it too

1 Like

Thank you, I wasn’t calling the function. Dah!

I am not getting the code, we have to generate random numbers from 0 to 1 in decimal numbers. Then why we declare result =0
while(result ===0) {
result = Math.random();
}

In my view we have to write the code like this
while(result !=0){
result = Math.random();
}

Any guidance please ?

1 Like

Can anyone tell me whats wrong in below code ? It works fine returns the result correctly in editor. But in freecodecamp environment it is failing all test cases.
function lookUpProfile(name, prop){ // Only change code below this line contacts.forEach(contact=>{ if(contact.firstName == name){ if(contact.hasOwnProperty(prop)) { console.log(contact.firstName ${contact.firstName} ${contact[prop]}); return contact[prop]; } else { return "No such property"; } } else { return "No such contact"; } }); // Only change code above this line }