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

210
Views
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
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!