The problem is that adding two numbers (the first one is created, then the second is added, plus, minus, divide or multiply, the second is created, and then everything goes together) an incomprehensible thing is displayed.
Here is the code:
var arrdigit = []; var arrdigit2 = []; for (var i = -1; i < 10; i++) { $("." + i).text(i); } for (var d = 0; d < 10; d++) { (function(d) { $("." + d).click(function() { arrdigit.push(d); $(".digit").text(arrdigit.join("")); }); })(d); } $(".plus").click(function() { totaldigit = arrdigit.join(""); $(".znak").text("+"); for (var j = 0; j < 10; j++) { (function(j) { $("." + j).click(function() { arrdigit2.push(j); $(".digit").text(arrdigit2.join("")); }); })(j); } }); $(".umnoj").click(function() { totaldigit = arrdigit.join(""); $(".znak").text("x"); for (var k = 0; k < 10; k++) { (function(k) { $("." + k).click(function() { arrdigit2.push(k); $(".digit").text(arrdigit2.join("")); }); })(k); } }); $(".delit").click(function() { totaldigit = arrdigit.join(""); $(".znak").text("÷"); for (var l = 0; l < 10; l++) { (function(l) { $("." + l).click(function() { arrdigit2.push(l); $(".digit").text(arrdigit2.join("")); }); })(l); } }); $(".minus").click(function() { totaldigit = arrdigit.join(""); $(".znak").text("-"); for (var y = 0; y < 10; y++) { (function(y) { $("." + y).click(function() { arrdigit2.push(y); $(".digit").text(arrdigit2.join("")); }); })(y); } }); $(".equal").click(function() { var hn = parseInt(arrdigit.join(""), 10); var hm = parseInt(arrdigit2.join(""), 10); console.log(hn + hm); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> For example, with the addition of 25 and 31, 2562 is displayed, although I looked at the typeof (hn and hm) are equal to the number and should be added as usual int'y. What can it be connected with and how can this be fixed?