Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda