I would like some advice on how to slim down this switch:
switch (lotUser | winningLot) {
case lotUser === winningLot[0]:
case lotUser === winningLot[1]:
case lotUser === winningLot[2]:
case lotUser === winningLot[3]:
case lotUser === winningLot[4]:
case lotUser === winningLot[5]:
case lotUser === winningLot[6]:
case lotUser === winningLot[7]:
console.log("You win!");
break;
default:
console.log("You do not win!");
break;
}
Instead of
case lotUser === winningLot[0]:
I wrote the script to be:
switch (lotUser | winnendLot) {
case lotUser === winnendLot[0|1|2|3|4|5|6|7]:
console.log("You win!");
break;
default:
console.log("You do not win!");
break;
}
I just don't know if this works the way I want it to work. It needs to check if the generated lotUser is equal to one of the values in an array (winningLot). If the lotUser equals one or more of the values in the winningLot array, it should output "You win!". Could someone please confirm that my code does the description I gave?
|character. It is a bitwise or operation. So you are actually doing some math between the operators, not choosing one or the other developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…|is binary OR.0|1|2|3|4|5|6|7will always be equal to7so that there is your first issue.|in the first line). It doesn't get more bite size than that.