I have been trying to make a variable have two values/be a condition. It’s fine if this is not possible, but I would like to not have to type 68 || 39 every time I would like to check. I have tried var left = 68 || 39 and var left = 68 && 39, but neither of those work. The variable is to check an event.keyCode number. I am trying to make my first game-in-javascript. Is this possible and if so how?
>Solution :
I don’t believe there is a way to make a variable be a condition but what you can do is define a method that checks if the value is 69 or 39.
For example:
function valueIs69or39(valueToCheck) {
return valueToCheck == 69 || valueToCheck == 39;
}
now you can just use if (valueIs69or39(value)) to check, and you can shorten the method name to make it easier to type.
Hope this helps!