I'm writing a code at the moment where I want to install network-shared printers automatically. Which printer the script should install depends on whether a user works for example in Sales or HR. I wanted to solve this problem with a switch
statement, but the problem is that it always matches the first value.
I tried several combinations of continue- or break-points, but none of them lead to my desired result.
$a = "HR"
switch ($a) {
{"Marketing", "Sales"} { "1" }
{"Sales Department", "HR"} { "2" }
"EDV" { "3" }
}
Output:
1 2
Normally, the console output should be "2", but it is "1" "2".
The switch can includes multiple cases where each case represents a particular value. Code under particular case will be executed when case value is equal to the return value of switch expression. If none of the cases match with switch expression value then the default case will be executed.
Use the fall-through feature of the switch statement to use a switch case with multiple arguments in JavaScript. A matched case will run until a break (or the end of the switch statement) is found.
Change the condition block to:
{$_ -in "Marketing", "Sales"}
This way both terms will match the switch case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With