Q:

Generating and checking random numbers in JavaScript

I have some problems with JavaScript. 
So far, I have this code:
<!DOCTYPE html>
<html>
<body>

<p>This program generates random numbers from 100 to 999.</p>

<button onclick="maingen()">Start</button> <-- Here's the FUNCTION OF FUNCTIONS..It should generate 3 digits, but only generates 1 :(

<p id="numbers"></p>

<script>
function generate1() {
    var a = Math.floor((Math.random() * 9) + 1);
    document.getElementById("numbers").innerHTML = a; <--generating the first digit (from 1 to 9)
}

function generate2() {
    var b = Math.floor((Math.random() * 9) + 0);
    document.getElementById("numbers").innerHTML = b; <--generating the second digit (from 0 to 9)
}

function generate3() {
    var c = Math.floor((Math.random() * 9) + 0);
    document.getElementById("numbers").innerHTML = c; <--generating the third digit (from 0 to 9)
}
function maingen(){
    generate1();
    generate2();
    generate3();
}

</script>

</body>
</html>

And it doesn't work like I intended to. It should generate a random number from 100 to 999. 
(I am generating separate digits because later I will need to check if there are same digits in that number (for example 222)).
So what did I do wrong? Any kind of help would be nice. Thank you.

A:

You could do it using the += in each function or you could simplify it a little more.
function generate1() {
    return Math.floor((Math.random() * 9) + 1);
}

function generate2() {
    return Math.floor((Math.random() * 9) + 0);
}

function generate3() {
    return Math.floor((Math.random() * 9) + 0);
}

function maingen() {
    var a = generate1();
    var b = generate2();
    var c = generate3();

    document.getElementById("numbers").innerHTML = a + '' + b + '' + c;
}

You can also do it like this
function generate_rand() {
    return Math.floor((Math.random() * 9));
}

function maingen() {
    var a = generate_rand() + 1;
    var b = generate_rand();
    var c = generate_rand();

    document.getElementById("numbers").innerHTML = a + '' + b + '' + c;
}

