A switch works by comparing what is in switch() to every case . works like: if (cnt === 1) … if (cnt === 2) … if (cnt === 3) … Therefore, you can’t have any logic in the case statements .
Read moreCan we write condition in switch case?
No. It’s not possible because a case must be a constant expression.
Read more