-2
When I do an operation, the result is always the same: Nan. What my mistake?
function show() {
var oper = document.querySelector('input[name="oi"]:checked').value;
return oper;
}
function tabuada(oper) {
var x = document.getElementsByTagName('input')[5].value;
var y = document.getElementsByTagName('input')[6].value;
if (oper == 'add') {
document.getElementById('resultado').innerHTML = '<h2>' + x+y + '</h2>';
}
else if (oper == 'sub') {
document.getElementById('resultado').innerHTML = '<h2>' + x-y + '</h2>';
}
else if (oper == 'div') {
document.getElementById('resultado').innerHTML = '<h2>' + x/y + '</h2>';
}
else {
document.getElementById('resultado').innerHTML = '<h2>' + x*y + '</h2>';
}
}
<h3>Selecione a operação desejada:</h3>
<form>
<input type="radio" name="oi" value="add">
<label for="add">Adição</label><br>
<input type="radio" name="oi" value="sub">
<label for="sub">Subtração</label><br>
<input type="radio" name="oi" value="mult">
<label for="mult">Multiplicão</label><br>
<input type="radio" name="oi" value="div">
<label for="div">Divisão</label><br>
<input type="submit" name="oi" onclick="show()" value="GO!">
</form>
<div>
<h3>Operar: </h3>
<input type="number" name="oia"><br>
<input type="number" name="oia">
<input type="submit" name="oia" value="GO!" onclick="tabuada()">
<h2>O resultado é: </h2>
<p id="resultado"></p>
</div>
<script src="teste.js"></script>
How about you describe what your code should do? There is one fluffy only, two "Go" buttons and some fields out of the form. Not to mention that in function
tabuada
you expect a parameteroper
, but on the call, on the eventclick
, you don’t pass a value.– Woss
I think that’s the problem, I can’t pass the parameter
oper
for the tabulated function– nelson450
Everything is missing, in fact.
– Jéf Bueno
I must select the desired operation, click GO! , write the numbers and do the operation;
– nelson450