Syntax error in "else if"

-6

With this function my program works, but when I add another condition of the error:

if ((nota >= 6) && (frequencia >= 75)){
   alert("Aprovado");
}
else if (frequencia >= 50){
   alert("Recuperação");
}
else{
   alert("Reprovado");
}

I want to add one more condition to this error:

    if ((nota >= 6) && (frequencia >= 75)) {
        alert("Aprovado");
    }
    else if (frequencia >= 50) {
        alert("Recuperação");
    }
    else {
        alert("Reprovado");
    }

    //essa
    else if (nota >= 4) {
        alert("Aluno de Recuperação");

    } else {
        alert("Aluno Reprovado");
    }
}
    
asked by anonymous 02.03.2018 / 18:17

1 answer

3

else if can not go after else { . The else must be the last condition, it says something like, all the others are false, so you must execute it. The correct one would be to understand logic first.

I assume that note and frequency are important, but only alert can be displayed at a time, there is a lot of strange thing in your conditions, but I believe that if frequency below 50 and note below 4, then both can split the even else

If the student needs to have frequency 50 or grade 4 (both are not needed at the same time), then the correct one should be:

if (nota >= 6 && frequencia >= 75) {
    alert("Aprovado");
}
else if (frequencia >= 50) {
    alert("Recuperação");
}
else if (nota >= 4) {
    alert("Aluno de Recuperação");
} else {
    alert("Aluno Reprovado");
}

But both are necessary, at least the student has a frequency equal to or greater than 50 and a grade equal to or greater than 4, this at the same time, to be of recovery:

if (nota >= 6 && frequencia >= 75) {
    alert("Aprovado");
}
else if (frequencia >= 50 && nota >= 4) {
    alert("Aluno de Recuperação");
} else {
    alert("Aluno Reprovado");
}
    
02.03.2018 / 18:25