Javascript Calculator [Problem Help]

Hi Campers,

This is my Javascript Calcalator Project Links - https://codepen.io/tanwanjern/pen/gRpObx?editors=1111

My Question is why the number buttons only work after i click the AC button?

Lester

You initialize inputs with an empty array. So this will give an error:

if(inputs[inputs.length-1].indexOf("+","-","/","*",".")===-1)

because you are trying to access inputs[-1].

The AC button resets inputs with inputs=[""]. Which means there is always an item there and the if statement won’t give an error.

So instead of var inputs = [];, you will need var inputs = ["];

1 Like

Wow, Thank you very much !