Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Why does the below code not print anything?

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;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!