problem with sum parseInt ()

2

I'm trying to add more "1" with parseInt () to the number but it always returns the original number with "1" next to it, for example 10 + 1 it returns me 101 (hit mizeravi). Note: I'm using split because in my full function I return to several different div's different values.

 function teste(conteudo) {
      dados = conteudo.split('|');
      var adicicaoEstoque = parseInt(dados[1] + 1);
      document.getElementById(dados[0]).innerHTML = adicicaoEstoque;
 } 
<button onclick="teste('resultado|10')">adicione + 1</button>
<div id="resultado"></div>
    
asked by anonymous 14.06.2018 / 19:20

1 answer

4

The correct would be to first convert "10" and then add 1, otherwise it does the "10" + "1" operation which gives "101".

Look like this:

var adicicaoEstoque = parseInt(dados[1]) + 1;

function teste(conteudo) {
    dados = conteudo.split('|');
    var adicicaoEstoque = parseInt(dados[1]) + 1;
    document.getElementById(dados[0]).innerHTML = adicicaoEstoque;
} 
<button onclick="teste('resultado|10')">adicione + 1</button>
<div id="resultado"></div>
    
14.06.2018 / 19:28