Home > Net >  I created a function that generates a random number which is contained inside the variable. I run th
I created a function that generates a random number which is contained inside the variable. I run th

Time:03-28

function nextSequence() {
    var randomNumber = (Math.floor(Math.random() * 3)   1);
}

i ran this on the console yet only got undefined i dont know what is wrong with this. any help is appreciated

CodePudding user response:

If you want to use this number outside of the function, you need to return it from the body of the function and then call the function itself:

function nextSequence() {
  return Math.floor(Math.random() * 3)   1;
}

const num = nextSequence();

console.log(num);

  • Related