JS - Calculate a random number

JavaScript - Calculate a random number

randomNumber() {
    return Math.floor(Math.random() * 3) + 1;
}

This would calculate for a random integer between 1 and 3.


randomNumber() {
    return Math.floor(Math.random() * 10);
}

This would calculate for a random integer between 0 and 10.


randomNumber() {
    return Math.random() * 10;
}

This would return any number (with floating point) between 0 and 10, e.g 0.5324436885587769 or 7.830256170505805

results for ""

    No results matching ""