Ask coding questions

← Back to all posts
slice not working
dObbOb11 (13)

Calculator Broken

I tried to make a JavaScript calculator where you can do this sort of thing:

3*4

and get the result printed to the console

but something does not work (I am not sure what as I do not recieve an error but I think it may be indexOf(); on line 4) I tried to debug it but got confused. :(

Edit:
that is fixed but now (thanks @Coder100!) it says [typescript] Expression expected.
when you hover over the } symbol on line 18

Answered by Coder100 (18057) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18057)

Here is your error:

!input.indexOf("+") == -1

It gets evaluated like this:

(!input.indexOf("+")) == -1

What you want is:

!(input.indexOf("+") == -1)

or even better:

input.indexOf("+") != -1

line 4

dObbOb11 (13)

thanks @Coder100! it fixed the !input.indexOf("+") == -1 problem