-2

I want to make random three digit number but when I run it, it generates alphanumeric characters. I want to just get a random three digit number.

generate:

function () {
    this.newItem.st = Math.random().toString(36).substring(2, 3).toUpperCase() +
                      Math.random().toString(36).substring(2, 4).toUpperCase()
}

Scren shot

When I click generate I want to get random values of just 0-9 not A-Z.

F. Hauri - Give Up GitHub
  • 64,122
  • 17
  • 116
  • 137

1 Answers1

0

Multiply your random number by 10 to get into the one's place, use Math.floor to get an integer, and then convert to string to get a string of numbers:

const el = document.getElementById("output");
el.innerHTML = getNumber();
function getNumber() {
    let myNum = Math.floor(Math.random() * 10).toString() + Math.floor(Math.random() * 10).toString() + Math.floor(Math.random() * 10).toString();
    return  myNum;
}
dikuw
  • 1,134
  • 13
  • 22