Search code examples
javascriptcalculatorkeypresskeycode

Using keypress to target two different keys within same expression?


I am building a calculator in vanilla JS and currently have this expression to handle the multiplication:

if ((isShift == true && event.keyCode == 56) || event.keyCode == 106){
  calc.passMethod('multiply');
} 

So if someone holds Shift+8 it will multiply. How can I make it so that if someone also hits x that it will multiply?

Here would be the function if it was for x:

if (event.keyCode == 88 || event.keyCode == 106)

Any help would be great! Thanks!


Solution

  • if ((isShift == true && event.keyCode == 56) || event.keyCode == 106 || event.keyCode == 88)
    {calc.passMethod('multiply');}