0
I made a code that prints a sequence of numbers, from the number typed to the end, but when printing it the last number is not appearing.
Example: first number typed is 3 and the second is 7. The sequence would be 3, 4, 5, 6, 7, but 7 does not appear.
function id(valor_campo)
{
return document.getElementById(valor_campo);
}
function getValor(valor_campo)
{
var valor = document.getElementById(valor_campo).value;
return (valor);
}
function nums(valores)
{
var inicio = getValor("num1");
var fim = getValor("num2");
var res = 0;
while (inicio < fim)
{
res += (inicio)+"<br>";
inicio++;
}
document.getElementById("demo").innerHTML = res;
}
<html>
<head>
<meta charset="utf-8">
</head>
<body>
Valor 1: <input type="number" name="num1" id="num1"> <br><br>
Valor 2: <input type="number" name="num2" id="num2"> <br><br>
<button onclick="nums()">Saiba a sequência dos números digitados!</button>
<p id="demo"></p>
</body>
</html>
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero