0
I’m starting to study programming and JavaScript I had an obstacle with the if/else.
In the code, the if always performs, but the else no, I’ve made several modifications (including adding the addEventListener in the JavaScript to call the event of click) but never runs the whole code, where I’m missing?
Follows the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nacionalidade</title>
</head>
<body>
<h1>BRASILEIRO OU ESTRANGEIRO?</h1>
Digite o seu país de origem:<input type="text" name="pais" id="pais">
<input type="button" value="Verificar" onclick="clique()">
<script>
function clique(){
let pais='Basill'
if(pais!=='Brasil'){
alert(`Você é ESTRANGEIRO!`)
} else{
alert(`Você é BRASILEIRO`)
}
}
</script>
</body>
</html>
that code falls on
elseI didn’t understand the doubt– Ricardo Pontual
what is the problem? already seen that by fixing a value in the variable parents will always enter in Else?
– novic
your doubt is because you have the text box to type the country?
– novic
If the variable
paisnever changes, your program will always behave the same way. There is a logical flaw there. Note that at no time do you collect the value the user entered in the input. To do thislet pais = document.getElementById('pais').value.– yoyo
Basill will always be different from Brazil.
– Augusto Vasques
Thanks for the help I understood where I went wrong at first but this is the only logic error? Because I continue with the same problem.
– Tati Bezerra