Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda