-1
The 'program' is this:
function verificar() {
var país = document.getElementById('querochora')
var res = document.getElementById('res')
if (país != 'Brasil') {
res.innerHTML = 'Você é estrangeiro.'
} else {
res.innerHTML = 'Você é <strong>Brasileiro</strong>.'
}
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VERIFICADOR DE PAÍS.</title>
</head>
<body>
<h1>Digite abaixo o seu país.</h1>
Seu país: <input type="text" name="país" id="país">
<input type="button" value="Verificar" onclick='verificar()'>
<div id='res'>
</div>
</body>
</html>
For some reason he’s wrong, someone can tell why?
Test like this
if (país.value != 'Brasil')
– Augusto Vasques
you have to exchange the id of the element in javascript for
país
. For the element with idquerochora
does not exist in your html. In addition to setting @Augustovasques– Danizavtz
Thanks kkk You can explain to me what this means (.value)?
– Lucas Fonseca
Also try to explain the problem, not only say you have a mistake, so make life easier for those who are trying to help.
– tvdias
And avoid using accents and special characters now! Whether for variable names or filenames!!
– tvdias
The reason to use the
.value
is thatdocument.getElementById
te returns an HTML element, an input, in the case. The input has a property called value, which is where the "value" of the input is.– tvdias
I would also say that the question should be closed as a "typo", since the problem is changing the name of the element...
– tvdias
O . worth will take the value of the field, in case your field is
pais
and it will take the value of this field (input).– Dakota