Okay, so my problem is that I have three random number generators and I want the value of all three randomly generated numbers (generated from 1-5) to add up to 9. For example, I randomly generate a 4, a 3 and a 2. And on another click of the button, a 5, a 3 and a 1. I've tried for a while to do this but just can not figure it out.
function statGen() {
var x = document.getElementById("number");
x.innerHTML = Math.floor((Math.random() * 5) + 1);
var a = document.getElementById("agl");
a.innerHTML = Math.floor((Math.random() * 4) + 1);
var l = document.getElementById("lck");
l.innerHTML = Math.floor((Math.random() * 3) + 1);
}
<button id="statbutton" onclick="statGen()">Get Numbers</button>
<p id="main">Main:</p>
<p id="number"></p>
<br/>
<p id="Agl">Agl:</p>
<p id="agl"></p>
<br/>
<p id="Lck">Lck:</p>
<p id="lck"></p>
I have tried to run it through a loop multiple times until it was the number 9, but none of those worked.