I'm trying to use a for loop to give values to three vars (but it could be 2 or even 100 vars, that's not the problem, I guess), and I want to use the value of i to indicate a var name with the name "num1" for example making the code look like num[i] = x or num + [i] = x (I tried both but none worked). I'm not sure what I am doing wrong. Here's my code so far:
function numbers() {
var num1, num2, num3 = 0;
for (var i = 1; i < 4; i++) {
num[i] = Math.floor(Math.random() * 999);
document.getElementById("n1").innerHTML = num[i];
}
}
I also want to make the document.getElementById("n1").innerHTML get the number in "n[number]" from the I value, something like "n" + [i], but it doesn't work neither.