Help with the calculator

Help with the calculator


Hi everyone!
I have been working on my calculator for about two weeks now. I got most of the functionality down pretty fast, but am stuck on two thing.

  1. Currently a user cannot input two consecutive dots, but they can do something like this 1.2.3 + 5. How can I prevent that from happening?

  2. After user gets a total , if they press a number, that number just gets tacked on to the back of the total. So, if the total is 12, and the user presses 3, they have 123 in the input field, and fututre calculations are performed on 123. I want it to be so that when the user presser a number, it resets the calculator to that number. So if your total is 12 and you press + 3, you get 15, but if you just press 3, all future calculations will be preformed on 3.

Please let me know if I didn’t explain the issues well. Here is my code,

Thank you in advance


You can use includes on the input array itself.

if (input.includes('.')) {

You can keep a boolean hasComputed variable that keeps track whether a calculation has just been recently performed. It defaults to false, and switches to true if the user hits the equals button, and back to false when a reset is executed. When you press a button, it will check first if hasComputed is true, in which case it will call the reset function.


Thank you so much for your help.