JS Calculator Feedback and need Help for a Bug

JS Calculator Feedback and need Help for a Bug
0.0 0

#1

Hello campers,

Please find my calculator here: http://codepen.io/ashvini45/full/RKNPYR/

I have a problem with my code. Supose I have to do 2.3 - 1.2 (or something similar) then I am unable to do it. Please guide me how can I handle multiple ‘dots’ in different number. and please share your feedback.

Thanks
Ashvini


#2

I am going to move this from project feedback to questions, because it is more about a bug than a general overview, and you will get much faster help.


#3

Instead of doing inputs.includes("."), you can check for a decimal in each number. Try splitting up the string into a number, then operator, then number, etc. and check each number for a decimal. There are many ways, the main thing to remember is that you can’t check the whole string for a number, you need to check after each number input (or before an operator)


#4

As far as the styling goes, you should either make your container larger, or the buttons smaller so that they will all fit in the intended row.


#5

Hello,

I have some suggestions.

I noticed the calculator doesn’t let you lead with a decimal even if the first set of numbers didn’t have decimals.

1+.1 is not allowed for example.

And the CE button seems to break the calculator until AC is pressed when CE is pressed while the calculator is empty.

You have a line that doesn’t allow any more decimals after there’s already one in “inputs”. Soo either add an exception or change whether it checks decimals in “inputs” in its entirety at all.

It helps to use alert() on certain variables when you feel they might be interfering with your code.

I went the lazy route and didn’t even check whether the user puts a bunch of decimals. The eval() function doesn’t work if there’s decimals in the wrong places and I assume the user knows where decimals should belong.


#6

Hi jx2bandito,

Thanks for pointing the issues. I will update the code ASAP.