Using the if & switch is breaking the code

Using the if & switch statements in the calcValue function breaks the code & I cant figure out whats wrong.

Thanks for all the help. :slight_smile:

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36.

Challenge: Build a JavaScript Calculator

Link to the challenge:

You’re redeclaring the variable. switch has crappy scoping rules. Put let myVar before the switch, then assign to myVar = in each branch

1 Like

Thanks! that worked.

Whats wrong here in the if statement? it doesn’t seem to work…

const digits = /[\d]/;
    
      if(this.props.padBank.keyTrigger == digits)

You’re saying “if (value is literally equal to this regex)” – for it to be true, and if you could actually do that (you can’t), keyTrigger would have to literally be /\d/

if (digits.test(this.props.padBank.keyTrigger)
1 Like