Below are different buttons ranging from 1 to 9 that I have:
<button type="button" onclick="calculatorNumber(1)">
When clicked, the following function is triggered:
function calculatorNumber(i) {
myNumbers.push(i);
var x = document.getElementById("screen").innerHTML = myNumbers.join("");
However, the function is not working as intended. For example, if I click on 3 and then 4, instead of storing them together as '34', they are stored separately at [0] and [1]. Any ideas on how to make them store as one value?
I attempted to improve the function with the following code, but it did not resolve the issue:
function calculatorNumber(i) {
myNumbers.push(i);
var x = document.getElementById("screen").innerHTML = myNumbers.join(""); // joining into one without comma
myNumbers = []; // emptying the array
myNumbers.push(x); // pushing the new combined value back in