I need to solve this exercise for the faculty and I'm not being able to. Someone could help me?
The letter says: "Enter two numbers and when pressing a button show all the numbers between those two numbers (inclusive). Consider the case that the numbers are entered inverted (first the largest and then the smallest)"
- This was what I did:
function Ejercicio8() {
let resultado = 0;
let numero1 = Number(document.querySelector("#txtNumero8").value);
let numero2 = Number(document.querySelector("txtNumero8A").value);
while (i <= numero2) {
if (numero1 > numero2) {
document.querySelector("#pResultado8").innerHTML += resultado + " ";
}
i--
}
}
Thank you!
Try this:
Changes made:
Add the
#
atxtNumero8A
in the querySelector .Locate which number is greater and which is less and assign it to the greater and lesser variables .
Execute a for loop that loops through all the numbers between the smallest and largest and displays the results
Unless you want to show them in inverted mode, which could be like this:
They already answered you but I'll pass you my version in case it helps you:
I just do some other validation more, I add the onclick event to a button so that it shows the results in a div, and it always runs from the smallest to the largest number, it doesn't matter which of the 2 it is, but you adjust that according to what you need modifying. But the answer above is fine.