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 Intergers
startValue = parseInt(startValue);
endValue = parseInt(endValue);
if(Number.isInteger(startValue) && Number.isInteger(endValue)){
// we call generateNumbers
let numbers = generateNumbers(startValue, endValue);
// we call displayNumbers
displayNumbers(numbers);
}else{
alert("Please enter a valid number");
}
}
// generate numbers from startvalue to the endValue
// logic functions(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];
// determine if a number is even or odd
if(number % 2 == 0){
className = "even";
}else{
className = "odd";
}
// This does render correctly with Prism see the source
templateRows += `${number} `;
templateRows += `${number}
// Get results from template rows
document.getElementById("results").innerHTML = templateRows;
}
}
The code is in four different functions to make it easier to use the Model View Controller (MVC) method.