The Code for Evengine
//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;
//Need to validate input
//parse into integers
startValue = parseInt(startValue);
endValue = parseInt(endValue);
if (Number.isInteger(startValue) && Number.isInteger(endValue)) {
//call generateNumbers
let numbers = generateNumbers(startValue, endValue);
//call displayNumbers
displayNumbers(numbers);
} else {
alert("You must enter integers");
}
}
//generate numbers from the startValue to the endValue
//logic function(s)
function generateNumbers(sValue, eValue) {
let numbers = [];
//get all numbers from start to end
for (let index = sValue; index <= eValue; index++) {
//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 (index % 5 == 0) {
//This line displays properly in the source file
templateRows += ``;
}
if (number % 2 == 0) {
className = "even"
}
else {
className = "odd"
}
//This line displays properly in the source file
templateRows += `${number}`;
if ((index + 1) % 5 == 0) {
//This line displays properly in the source file
templateRows += ``;
}
}
document.getElementById("results").innerHTML = templateRows;
}
The Code is structured in three functions.
getValues
This is a function that gets two values from an HTML form and parses them into integers. The integers are then passed to the function generateNumbers and then to the function displayNumbers. for displaying of the numbers to the screen.
generateNumbers
This is a function that takes two numbers and then uses the numbers to generate an array of numbers using a for loop. The size of the array depends on the range of the two numbers. The number array is then returned by the function.
displayNumbers
This is a function that takes an array of numbers and displays them onto an HTML web page using a for loop. Odd numbers are displayed in regular text and even numbers are displayed in bold text.