0

I do not know why it is not working. It is supposed that when you got a mark between 90 or more that equals A. When you got between 80 and 89 that equals B and so on...

let nota = prompt("Ingrese su nota: ");


if (nota >= 90){
  console.log(nota + " " + "equivale a una A");
}

else if (nota == 80  ||  nota <= 89){
  console.log(nota + " " + "equivale a una B");
}
else if (nota == 70  ||  nota <= 79){
  console.log(nota + " " + "equivale a una C");
}
else if (nota == 60  ||  nota <= 69){
  console.log(nota + " " + "equivale a una D");
}
else{
  console.log("Tienes una F");

}
1
  • You might want to use switch here Commented Jul 7, 2018 at 5:58

3 Answers 3

1

Your problem is that in the second test:

nota == 80  ||  nota <= 89

every value of 89 or less will pass and so they'll all get a B. Note also that the test nota == 80 is redundant since 80 is also <= 89, so the test is equivalent to:

nota <= 89

Of course you could do:

nota >= 80  &&  nota <= 89

but that's more complex than it needs to be. You can simplify the test since if else means it will stop testing once one test is true, so just use >= and the lower value for all tests:

let nota = prompt("Ingrese su nota: ");

if (nota >= 90){
  console.log(nota + " " + "equivale a una A");
  
} else if (nota >= 80) {
  console.log(nota + " " + "equivale a una B");

} else if (nota >= 70) {
  console.log(nota + " " + "equivale a una C");

} else if (nota >= 60) {
  console.log(nota + " " + "equivale a una D");

} else {
  console.log("Tienes una F");
}

The tests have to be in the correct sequence, so if the value is 90 or greater, the first test is satisfied and no others are tested. If the value is say 82, the first test fails so it goes to the next test, which passes so the result is a B and again, no further tests are tried.

And so on for other values, so if the value is say 55, all the tests fail and it goes to the final else.

Sign up to request clarification or add additional context in comments.

Comments

0

Replace expression as nota >= 80 && nota <= 89 and etc.

Comments

0

use this code

 let nota = prompt("Ingrese su nota: ");
if (nota >= 90){
  console.log(nota + " " + "equivale a una A");
 
}

else if (nota <= 89 && nota >= 80 ){
  console.log(nota + " " + "equivale a una B");

}
else if (nota <= 79 && nota >= 70){
  console.log(nota + " " + "equivale a una C");
  
}
else if (nota <= 69 && nota >= 60){
  console.log(nota + " " + "equivale a una D");

}
else{
  console.log("Tienes una F");

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.