Javascript Calculator [Problem Help]

Hi Campers,

This is my Javascript Calcalator Project Links -

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


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


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 !