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

217
Views
Check two variables in js switch case

I have 2 variables that return true and false. And I want each one that was false to return the corresponding text. How to handle this ValidCheked and repeatChecked in the switch?

   export const checked = (e, options) => {
    
      const nameCheked = new RegExp("^[a-zA-Z0-9]{1,50}$");
    
      const repeatChecked = options.every(
        (pool) => pool.text.toLowerCase() !== e.target.value.toLowerCase()
      );
      const validCheked = nameCheked.test(e.target.value);
    
      switch (repeatChecked) {
        case true:
          return {
            type: true,
            text: "looks good"
          };
        case false:
          return {
            type: false,
            text: "repeatName"
          }
        case validCheked = true:
          return {
            type: true,
            text: "looks good"
          }
        case validCheked = false:
          return {
            type: true,
            text: "Invalid name (no special character)"
          }
        default:
          return {
            type: false,
            text: "looks good"
          }
      }
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use switch structure like this:

switch (true) {
 case (repeatChecked== true && validCheked == true):
   //do something (if you return something here, don't need to break;)
   break;
 case (repeatChecked== false && validCheked == false):
   //do something (if you return something here, don't need to break;)
   break;
  ...
}
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!