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

113
Views
If/Else Statement Failing

I'm trying to write a simple script that will look at a credit number rating and show the corresponding text rating. The if-else statement breaks when I get to the second else/if statement and I cannot figure out why so anything over 601 just reads "POOR".

credit = 690;

if (credit <= 600) {
    document.write("VERY POOR");
} 
else if (credit >= 601 || credit <= 657){
    document.write("POOR");
}
else if (credit >= 658 || credit <= 719){
    document.write("FAIR");
}
else if (credit >= 720 || credit <= 780){
    document.write("GOOD");
}
else {
    (credit >= 781 || credit <= 850);
    document.write("EXCELLENT");
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

The problem of your code is that when you code:

else if (credit >= 601 || credit <= 657){
    document.write("POOR");
}

This is true, so it will say POOR, because you are dealing with or clause witch means (True or False) = (False or True) = True:

The solution is removing the first argument:

let credit = 690;

if(credit <= 600) {
    console.log(credit)
    document.write("VERY POOR");
} 
else if (credit >= 601 && credit <= 657){
    console.log(credit)
    document.write("POOR");
}
else if (credit >= 658 && credit <= 719){
    console.log(credit)
    document.write("FAIR");
}
else if (credit >= 720 && credit <= 780){
    console.log(credit)
    document.write("GOOD");
}
else {
    (credit >= 781 && credit <= 850);
    console.log(credit)
    document.write("EXCELLENT");
}

ps: Code need the 'and' clause (&&) between the two values to work. Because, (True and False) = (False and True) = (False and False) = False. Its only true when when both members are true!

about 4 years ago · Juan Pablo Isaza Report

0

You should replace the || with &&.

|| means OR, meanwhile && means AND. You need to check if credit is greater than 601 AND lower than 657.

Try this way:

credit = 690;

if (credit <= 600) {
    document.write("VERY POOR");
} 
else if (credit >= 601 && credit <= 657){
    document.write("POOR");
}
else if (credit >= 658 && credit <= 719){
    document.write("FAIR");
}
else if (credit >= 720 && credit <= 780){
    document.write("GOOD");
}
else {
    (credit >= 781 && credit <= 850);
    document.write("EXCELLENT");
}
about 4 years ago · Juan Pablo Isaza Report

0

in these cases you must use the &&

&& Operator will define that the two values ​​need to be true, OR Operator will define that to execute, only one value is true.

you can read more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND

    let credit = 750;

if (credit <= 600) {
    document.write("VERY POOR");
} 
else if (credit >= 601 && credit <= 657){
    document.write("POOR");
}
else if (credit >= 658 && credit <= 719){
    document.write("FAIR");
}
else if (credit >= 720 && credit <= 780){
    document.write("GOOD");
}
else {
    (credit >= 781 && credit <= 850);
    document.write("EXCELLENT");
}
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!