Hi Im very stuck with I guess is very easy but I can’t find what I doing wrong… I tried to use the same condition in Node and it’s works, but when I applied in my code nothing happens.
<body>
<h1><strong></strong>Verificador de multas</strong></h1>
<input type="text" name="nmd" id="nmd" value="Digite">
<input type="button" value="ir" id="ir" onclick="clicar()">
<div id="res">
<h2>Resultado...</h2>
</div>
<script>
var idade = document.querySelector('input#nmd')
var val = Number(idade.value)
var res = document.getElementById('res')
function clicar () {
var val = 17
if (val < 16) {
res.innerHTML('Nao vota')
} else if (val < 18) {
res.innerHTML('Voto opcional')
} else {
res.innerHTML('Voto obrigatorio')
}
}
</script>
</body>
the terminal is a debugging tool
are you sure that the value of idade is the one you think?
you expect idade to be a number. But is it? How do you know if you don’t print the value of idade to the console with console.log(idade)?
The problem its no show the idade, its actually to give a answer depends of what do you put into the input… Because if I only put console.log(idade) I know what its going to show me of course.
I mean… the function only recognize the first last condition the ELSE. i dont know why…
I try the debug… its saying No debug adapter, can not send ‘evaluate’
<body> <h1><strong></strong>Verificador de multas</strong></h1> <input type="text" name="nmd" id="nmd" value="Digite"> <input type="button" value="ir" id="ir" onclick="clicar()"> <div id="res"> <h2>Resultado...</h2> </div> <script> var idade = document.querySelector('input#nmd') var n1 = Number(idade.value) var res = document.getElementById('res') function clicar() { if (n1 < 16) { console.log = (Nao vota) } else if (n1 < 18) { res.innerHTML = Voto opcional } else { res.innerHTML =Voto obrigado`
}
}
If you are expecting a number you should set the type attribute to number, not text. It made it unclear what you were trying to do (I thought you were looking at the number of characters, not just the value).