-4
function CalcularSoma(valor1, valor2, soma) {
var valor1 = document.getElementById("formValor1").value;
var valor2 = document.getElementById("formValor2").value;
var soma;
soma = parseInt(valor1) + parseInt(valor2);
document.getElementById("formResultado").value = soma;
}
function CalcularMult(valor1, valor2, mult) {
var valor1 = document.getElementById("formValor1").value;
var valor2 = document.getElementById("formValor2").value;
var mult = (valor1 * valor2);
document.getElementById("formResultado").value = mult;
}
function CalcularDiv(valor1, valor2, div) {
var valor1 = document.getElementById("formValor1").value;
var valor2 = document.getElementById("formValor2").value;
var div = (valor1 / valor2);
document.getElementById("formResultado").value = div;
}
function CalcularSub(valor1, valor2, sub) {
var valor1 = document.getElementById("formValor1").value;
var valor2 = document.getElementById("formValor2").value;
var sub = (valor1 - valor2);
document.getElementById("formResultado").value = sub;
}```
Simply declare the variable outside the function.
– JeanExtreme002
@Jeanextreme002 The problem of declaring out of function is happening that (and you don’t know if it’s going to happen because the question doesn’t give more details)
– hkotsubo
Can you explain the question better? I’m not sure what you’re trying to solve.
– Sergio
How are you calling these functions, Marcelo?
– Wan
by ultilizing the onclick event, however while trying to really avoid the repetition of the code by creating the variable in all functions the code of the error, I would like to understand better how to get remove them and stay a more visible code simply that, I’m starting now I have little knowledge in the language itself.
– Marcelo
@I wonder if you have a way to declare these variables out of function and power in other functions, not to be repeating in all functions the same variables value1 and value2.
– Marcelo