Your code is several errors, that line is wrong.
var verificador = document.window.getElementById('input#verificador');
var nacionalidade = document.window.getElementById('div#nacionalidade');
You can’t put the window after document and the getElementById cannot select selectors other than querySelector he only accepts the name of id.
var verificador = window.document.getElementById('verificador');
var nacionalidade = window.document.getElementById('nacionalidade');
And on the part of if you’re not comparing the value which is the value of input with id="verificador"
if (verificador == 'brasil' || verificador == 'BRASIL' || verificador == 'Brasil')
{
nacionalidade.innerText = 'Você é brasileiro';
}
Just put the value in front of verificador.
if (verificador.value == 'brasil' || verificador.value == 'BRASIL' || verificador.value == 'Brasil')
{
nacionalidade.innerText = 'Você é brasileiro';
}
Ready! That’s it, now it’s working perfectly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Teste de nacionalidade</h1>
Digite o país que você nasceu:<input type="text" name="verificador" id="verificador"/>
<input type="button" value="Clique e descubra sua nacionalidade " onclick="verificar()"/>
<div id="nacionalidade">Nacionalidade</div>
<script>
var verificador = window.document.getElementById('verificador');
var nacionalidade = window.document.getElementById('nacionalidade');
function verificar() {
if (verificador.value == 'brasil' || verificador.value == 'BRASIL' || verificador.value == 'Brasil') {
nacionalidade.innerText = 'Você é brasileiro';
} else {
nacionalidade.innerText = 'Você é estrangeiro';
}
}
</script>
</body>
</html>
Note: if the id of the element is
verificador, you must usegetElementById('verificador'). The value'input#verificador'would make sense only to use with thequerySelector.– Woss
That said, what should be
document.window?– Woss