# Calculator - multiplication function working differently than addition

**URL:** <https://forum.freecodecamp.org/t/calculator-multiplication-function-working-differently-than-addition/531997>\
**Category:** I Built This\
**Created:** [July 20, 2022, 7:51pm UTC](https://forum.freecodecamp.org/t/calculator-multiplication-function-working-differently-than-addition/531997 "2022-07-20T19:51:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![madscience1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/madscience1/32/277416_2.png) [@madscience1](https://forum.freecodecamp.org/u/madscience1)\
**Post date:** [July 20, 2022, 7:51pm UTC](https://forum.freecodecamp.org/t/calculator-multiplication-function-working-differently-than-addition/531997/1 "2022-07-20T19:51:31Z")

</div>

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](https://github.com/2bXorNot/Calculator_project)

This is how I solved it using the addition button:

```auto
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.

---

<div class="post-metadata">

**Author:** ![splendoribsmart](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/splendoribsmart/32/274688_2.png) [@splendoribsmart](https://forum.freecodecamp.org/u/splendoribsmart)\
**Post date:** [July 26, 2022, 4:14am UTC](https://forum.freecodecamp.org/t/calculator-multiplication-function-working-differently-than-addition/531997/2 "2022-07-26T04:14:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![madscience1](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/madscience1/32/277416_2.png) [@madscience1](https://forum.freecodecamp.org/u/madscience1)\
**Post date:** [July 30, 2022, 10:10pm UTC](https://forum.freecodecamp.org/t/calculator-multiplication-function-working-differently-than-addition/531997/3 "2022-07-30T22:10:37Z")

</div>

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](https://github.com/2bXorNot/calculator_simplified_2)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [January 29, 2023, 10:11am UTC](https://forum.freecodecamp.org/t/calculator-multiplication-function-working-differently-than-addition/531997/4 "2023-01-29T10:11:23Z")

</div>

Closed on January 29, 2023, 10:11am UTC

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