1
I am studying Javascript and I have the following problem:
<!DOCTYPE html>
<html lang="pr-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nacionalidade</title>
</head>
<body>
De onde você é?
<input type="text" name="nac" id="nac">
<input type="button" value="Verificar" onclick="verif()">
<div id="res">
</div>
<script>
var nac = document.getElementById('nac')
var res = document.getElementById('res')
function verif(){
if (nac == 'Brasil'){
res.innerHTML = `Você é brasileiro `
}else {
res.innerHTML = `Você é estrangeiro `
}
}
</script>
</body>
</html>
When running, the answer is always that of the Else structure, no matter what the user type, I could not identify the problem.
just add next to the
nac
,.value
will stay like thisnac.value
– Codigo de Senior
Has any answer worked out for you Alef?
– novic
It gave yes, I will continue doing tests to fix the matter, soon I return with more doubts, rsrs
– alef martins de souza