$\require{cancel}$
<Li> We will count from <span id="num1">? </span> to <span id="num2">?</span>
<div id="Output">
</div>
<label for="num1Input">Count From: </label>
<input type="number" id="number1Input" value=0>
<label for="num2Input">Count To: </label>
<input type="number" id="number2Input" value=0>
<input type="button" value = "Do Count" id="Button1" onclick="DoCount()"/>
<script>
"use strict"
function FillSpan (value, id) {
let element = document.getElementById(id)
element.innerHTML = value
}
function FillSpans(valueA, valueB){
FillSpan(valueA, "num1")
FillSpan(valueB, "num2")
}
function FindDirection(a,b) {
if (a < b) {
return "up"
} else if (a > b) {
return "down"
} else {
return "same"
}
}
function LogSame(value) {
let workArea = document.getElementById("Output")
workArea.innerHTML = "<h3> Count:</h3>"
workArea.innerHTML += "The numbers are the same the count is "
workArea.innerHTML += "<p> " + value.toString()
}
function ExecuteCount(start, stop, increment) {
let workArea = document.getElementById("Output")
let output
output = "<h3> Count:</h3>"
console.log(increment)
for (let i = start; i != stop; i += increment) {
console.log(start, stop, i, increment)
output += i.toString() + "<br>"
}
output += stop.toString() + "<br>"
workArea.innerHTML = output
}
function DoCount() {
let number1 = parseInt(document.getElementById("number1Input").value)
let number2 = parseInt(document.getElementById("number2Input").value)
FillSpans(number1, number2)
let countDir = FindDirection(number1, number2)
switch (countDir) {
case "up":
ExecuteCount(number1, number2, 1)
break
case "down":
ExecuteCount(number1, number2, -1)
break
default:
LogSame(number1)
}
}
</script>
span which is for in line control.
div which is for block control.
FindDirection
DoCount
innerHTML attribute of an element.