1
Hello, I have a problem with my Javascript code, I was doing an exercise but my code does not change the content of a div called "res". I already debugged the code and gave the following error:
var inicio = document.getElementById('txtinicio')
^
ReferenceError: document is not defined
While in the browser no error occurs.
HTML code:
<body>
<header>
<h1>Vamos contar</h1>
</header>
<section>
<div>
<p>
Início: <input type="number" name="txtinicio" id="txtinicio">
</p>
<p>
Fim: <input type="number" name="txtfim" id="txtfim">
</p>
<p>
Passo: <input type="number" name="txtpasso" id="txtpasso"> <br>
<br> <input type="button" value="Contar" onclick="verificar()">
</p>
</div>
<div id="res">
Preparando a contagem...
</div>
</section>
<footer>
<p>© Alex Faustino</p>
</footer>
<script src="script.js"></script>
</body>
Javascript code:
var inicio = document.getElementById('txtinicio')
var fim = document.getElementById('txtfim')
var passo = document.getElementById('txtpasso')
var res = document.getElementById('res')
var inicion = Number(inicio)
var fimn = Number(fim)
function verificar() {
if (inicio.value.length == 0 && fim.value.length == 0 && passo.value.length == 0) {
window.alert('[ERRO] Insira os dados!')
} else {
for (var c=inicion; c<=fimn; c++) {
res.innerHTML(c)
}
}
}
Thank you so much for all your help! :)
Voce already tried to put the whole point and comma at the end of each command? and complete its script tag with type="text/javascript"?
– Phill