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

110
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
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