I encountered this problem while trying to add the values of 6 different input, I noticed that if I add 3 of them it works, but if I add more than 3 values it doesn't work.
When I add 3 values between them, everything seems to work correctly but, for example, if I add 4 values, the result is like the addition between a string and a number.
May I have your help please? This is my HTML code for the imput tags:
document.getElementById("b").onclick = function() {
var x = document.getElementById("x").value;
var y = document.getElementById("y").value;
var z = document.getElementById("z").value;
var a = document.getElementById("a").value;
var b = document.getElementById("g").value;
var c = document.getElementById("c").value;
var risultato = parseFloat(x) + parseFloat(y) + parseFloat(z) + parseFloat(a) + parseFloat(g) + parseFloat(c);
document.getElementById("risultato").innerHTML = "La massa del prodotto è " + risultato;
}
<input type="number" placeholder="Valore 1" id="x" required>
<input type="number" placeholder="Valore 2" id="y" required>
<input type="number" placeholder="Valore 3 (se presente)" id="z">
<input type="number" placeholder="Valore 4 (se presente)" id="a">
<input type="number" placeholder="Valore 5 (se presente)" id="b">
<input type="number" placeholder="Valore 6 (se presente)" id="c">
<button class="btn btn-primary" id="b">Applica</button>
</form>