I am making a very simple game in html and javascript, the idea is that the user put the result of each operation, and if it is right, an alert appears for him. I wanted to use a table because I want to exercise this. The program is almost done, but I can not get the user to "submit" so I can check if it's right. I even tried to use a submit there, but I ended up doing a gambiarra that did not work. I searched on google and found nothing related. Right now ... J.G.
function olosko() {
var x = document.getElementById("tabela").rows[0].cells[4];
var y = document.getElementById("tabela").rows[1].cells[4];
var z = document.getElementById("tabela").rows[2].cells[4];
var r = document.getElementById("tabela").rows[3].cells[4];
x.innerHTML = "<input type='text'>";
y.innerHTML = "<input type='text'>";
z.innerHTML = "<input type='text'>";
r.innerHTML = "<input type='text'>";
var a = document.getElementById("tabela").rows[0].cells[0];
var b = document.getElementById("tabela").rows[0].cells[2];
var c = document.getElementById("tabela").rows[1].cells[0];
var d = document.getElementById("tabela").rows[1].cells[2];
var e = document.getElementById("tabela").rows[2].cells[0];
var f = document.getElementById("tabela").rows[2].cells[2];
var g = document.getElementById("tabela").rows[3].cells[0];
var h = document.getElementById("tabela").rows[3].cells[2];
a.innerHTML = parseInt(Math.random()*10);
b.innerHTML = parseInt(Math.random()*10);
c.innerHTML = parseInt(Math.random()*10);
d.innerHTML = parseInt(Math.random()*10);
e.innerHTML = parseInt(Math.random()*10);
f.innerHTML = parseInt(Math.random()*10);
g.innerHTML = parseInt(Math.random()*10);
h.innerHTML = parseInt(Math.random()*10);
if(a+b==x && c-d==y && e/f==z && g*h==r){
alert("VC GANHOU!");
}
}
<button onclick="olosko()">ESTOU PRONTO!</button>
<table id="tabela" border=1 width=400 height=400>
<tr>
<td></td>
<td>+</td>
<td></td>
<td>=</td>
<td></td>
</tr>
<tr>
<td></td>
<td>-</td>
<td></td>
<td>=</td>
<td></td>
</tr>
<tr>
<td></td>
<td>รท</td>
<td></td>
<td>=</td>
<td></td>
</tr>
<tr>
<td></td>
<td>X</td>
<td></td>
<td>=</td>
<td><div id="olosko()"></div></td>
</tr>
</table>
<submit><button>ACABEI!</button></submit>