Calculator - multiplication function working differently than addition

Hi there. I’ve spent pretty much the whole day trying to solve a issue but to no avail. Let’s say you are using a calculator: you press 3, +, 3 then +. The last + will act like the equals button, so if you press 9 and then +, you will get 15. This is what I’ve been working on. I was able to do it when it comes to addition and subtraction; however, multiplication and division are not working.

The code is on my Github: GitHub - 2bXorNot/Calculator_project: In this project, I am working on building a calculator that does basic arithmetic. HTML, CSS, JS

This is how I solved it using the addition button:

const addButton = () => {restrictCount();symbol = '+';count++;contador++;subArrLoops();sumAddition();clearSubArrAdded();forLoopClearArr();numbersArr[0].push(sum);numbersArr[1]; };

However, when I clear the sub-arrays with forLoopClearArr() after calling sumMultiplication(), I cannot multiply the numbers; it is as if the numbers need to be in the sub-arrays, but it’s not the case if I add or subtract.

After 6 plus hours, I really dunno what is up. Thanks.

There don’t seem to be any CSS attached to the web page, looking a the page source, it says there should be a .css file at ./css/calculator-css.css which I can’t find github link you provided. However I breeze your javascript, can’t really say much about it in, although I could see that you did a whole lot by yourself and that’s cool but a more efficient way to do simple calculations in JavaScript is to use the eval() function maybe you want to consider that in your next project i guess.

I will love to see how the calculator works so fix the css issue ASAP.

Thanks for taking the time to look through my code. I redid it from the ground up with the intent of making the code simpler, and it really helped. (So, if you are reading this, and you’re new to development like I am, heed me: always plan before you start coding; think through whatever you want to implement next; and work on making your code as simple as possible.) Anywho, for those interested, here’s the link to the Github repository: GitHub - 2bXorNot/calculator_simplified_2

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.