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

211
Visualizações
Is there a cleaner way to write this part of code, a lot of javascript if statements

Is there a cleaner way to write this part of code?
I feel like there are too much else if statements
It can most likely be done using switch statement but how cleaner or more readable will it be?

if (inflationArray.every((x) => x.value.length == 0)) {
    alert("Every field is empty");
    return;
  } else if (
    inflationArray[0].value.length == 0 &&
    inflationArray[1].value.length != 0 &&
    inflationArray[2].value.length == 0
  ) {
    alert("You didn't type in any money value or inflation rate");
    return;
  } else if (
    inflationArray[0].value.length == 0 &&
    inflationArray[1].value.length == 0 &&
    inflationArray[2].value.length != 0
  ) {
    alert("You didn't type in any money value or years");
    return;
  } else if (
    inflationArray[0].value.length != 0 &&
    inflationArray[1].value.length == 0 &&
    inflationArray[2].value.length == 0
  ) {
    alert("You didn't type in any year or inflation rate");
    return;
  } else if (inflationArray[0].value.length == 0) {
    alert("You didn't type in any money value");
    return;
  } else if (inflationArray[1].value.length == 0) {
    alert("You didn't type in any year");
    return;
  } else if (inflationArray[2].value.length == 0) {
    alert("You didn't type any inflation rate");
    return;
  }
about 4 years ago · Santiago Trujillo
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