The Code for HUNDO.
//get the values from the page
//starts or controller function
function getValues(){
//get values from the page
let startValue = document.getElementById("startValue").value;
let endValue = document.getElementById("endValue").value;
//parse into Integers
startValue = parseInt(startValue);
endValue = parseInt(endValue);
if(Number.isInteger(startValue) && Number.isInteger(endValue) && startValue >= 0 && endValue <= 100 && endValue >= startValue){
//we call generateNumbers
let numbers = generateNumbers(startValue, endValue);
//we call displayNumbers
displayNumbers(numbers);
}
else{
alert("You must enter valid integers");
}
}
//generate numbers from the startValue to endValue
//logic function(s)
function generateNumbers(sValue, eValue){
let numbers = [];
//we want to get all numbers from start to end
for(let index = sValue; index <= eValue; index++){
//this will execute in a loop until index= eValue
numbers.push(index);
}
return numbers;
}
//display the numbers and mark even numbers bold
//display or view functions
function displayNumbers(numbers){
let templateRows = "";
for (let index = 0; index < numbers.length; index++) {
let className = "even";
let number = numbers[index];
if(number % 2 == 0){
className = "even";
}
else{
className = "odd";
}
//This does not render correctly with Prism. See the source
templateRows += `${number} `;
}
document.getElementById("results").innerHTML = templateRows;
}
The Code is structured in three functions.
getValues()
getValues is responsible for getting the start and end values inputted by the user.
generateNumbers(sValue, eValue)
generateNumbers is responsible for generating all the numbers between the start and end values, this is done by a for loop that places each number in an array.
displayNumbers(numbers)
displayNumbers is responsible for displaying all the numbers from the array in a striped table on the page, while making the even numbers large in font and bolding it.