JenMorgan / js-learning

0 stars 0 forks source link

Create function random that returns random integer between two numbers #18

Open kartamyshev opened 4 years ago

kartamyshev commented 4 years ago

Example: random(20, 40).

Tip: Javascript has built in function Math.random() that returns random number between 0 and 1

JenMorgan commented 4 years ago
function randomInteger() {
    min = +prompt("number1");
    max = +prompt("number 2")
    return min + Math.ceil(Math.random() * (max - min));
  }

  alert(randomInteger());