Why does the ELSE Condition validate even if it is True?

Asked

Viewed 30 times

-4

 let valor=prompt("Digite um Numero:")

if(valor<20){
  alert("Valor menor que 20")}
if(valor==20){
  alert("Valor Igual a 20") }
    else {
  alert("Valor maior que 20")}

1 answer

1


The use of your parole is wrong.

From what I understand, a possible solution to your problem would be:

let valor=prompt("Digite um número:")

if(valor<20){ 
    alert("Valor menor que 20")
} else if(valor==20){ 
    alert("Valor Igual a 20") 
} else {
    alert("Valor maior que 20")
}

Note that we have a link of the conditional command if

  • That’s right, chaining ! thanks !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.