Calculator - stuck

Hi y’all. This is my first attempt at building a calculator with JS. I’m trying to return the correct process (adding, etc.).

Here’s my part of my code:

numbersArr = [[],[]];
console.log(numbersArr);

let cont = 0;
let final = 0;
let firstSubArrAdded  = '';
let secondSubArrAdded = '';
function equalsButton() {
    for(let i = 0; i < numbersArr[0].length; i++) {
        for(let k = 0; k < numbersArr[0][i]; k++) {
            firstSubArrAdded += numbersArr[0][k];
            console.log(firstSubArrAdded)
        };
    };
    for(let j = 0; j < numbersArr[1].length; j++) {
        for(let p = 0; p < numbersArr[1][j].length; p++) {
            secondSubArrAdded += numbersArr[1][p];
            console.log(secondSubArrAdded)
        };
    };
    
       addButton()
       subtractButton()

};

function addButton() {
    cont++
    final = (Number(firstSubArrAdded) + Number(secondSubArrAdded));
    console.log(final);
};
function subtractButton() {
    cont++
    final = (Number(firstSubArrAdded) - Number(secondSubArrAdded));
    console.log(final);
};

As you can see, I’m calling the addButton and subtractButton functions inside the equalsButton function as they return the processes. I tried creating this conditional to return the proper process but to no avail:

if(document.getElementById('button-add').clicked === true) {
    addButton()
    console.log(final);
};

I tried other things, but I’m stuck now. Sorry If I was verbose.

Do you have this on codepen or github? I think we need to see your entire project to make sense of what you are trying to do here.

I can tell you that

document.getElementById('button-add').clicked

looks very suspicious. I don’t know of a “clicked” attribute on an element. Are you adding that somewhere yourself?

I was able to figure it out:

let numbersArr = [[],[]];
console.log(numbersArr);
let count = 0;

//let addition
//let sum
let symbol = '';
let firstSubArrAdded = '';
let secondSubArrAdded = '';
//console.log(addition);

function equalsButton(){ 
    for(let i = 0; i < numbersArr[0].length; i++) {
        firstSubArrAdded += numbersArr[0][i];
        console.log(firstSubArrAdded);
        
    };
    for(let j = 0; j < numbersArr[1].length; j++) {
        secondSubArrAdded += numbersArr[1][j];
        console.log(secondSubArrAdded);
        
    };
    if(symbol === '+') {
        sum = Number(firstSubArrAdded) + Number(secondSubArrAdded)
        console.log(sum);
    };
    if(symbol === '-') {
        sum = Number(firstSubArrAdded) - Number(secondSubArrAdded)
        console.log(sum);
    };
    if(symbol === '*') {
        sum = Number(firstSubArrAdded) * Number(secondSubArrAdded)
        console.log(sum);
    };
    if(symbol === '/') {
        sum = Number(firstSubArrAdded) / Number(secondSubArrAdded)
        console.log(sum);
    };

};


function addButton() {
    count++
    symbol = '+';
};
function subtractButton() {
    count++
    symbol = "-";
};
function multiplyButton() {
    count++
    symbol = "*";
};
function divideButton() {
    count++
    symbol = "/";
};


function numberOneButton() {
    numbersArr[count].push('1');
};
function numberTwoButton() {
    numbersArr[count].push('2');
};
function numberThreeButton() {
    numbersArr[count].push('3');
};
function numberFourButton() {
    numbersArr[count].push('4');
};
function numberFiveButton() {
    numbersArr[count].push('5');
};
function numberSixButton() {
    numbersArr[count].push('6');
};
function numberSevenButton() {
    numbersArr[count].push('7');
};
function numberEightButton() {
    numbersArr[count].push('8');
};
function numberNineButton() {
    numbersArr[count].push('9');
};
function numberZeroButton() {
    numbersArr[count].push('0');
};
function periodButton() {
    numbersArr[count].push('.');
};