While I write switch(true) it produces the correct result, otherwise it does not produce any result. Why?
let age=18;
switch(age){
case age>18:
console.log("you can vote");
break;
case age<18:
console.log("you cannnot vote");
break;
}
The switch expression is a condition that can only work with equality == that's why it doesn't work in your case. you should use If-chains like this:
let age = 18;
if(age > 18)
{
console.log("you can vote");
}
else if(age < 18)
{
console.log("you can not vote");
}
The above code is the common solution for checking those types of conditions.