The Code
The code is structured in mutiple functions that utilizes for loops and boolean logic to complete the coding challenge.
function getValues()
This is the main function and is called when a user submits values for a range of numbers on the page. It uses the document.getElementById() method to retrieve the start and end values that the user has submitted. These values are then parsed as ints via the parseInt() method and are checked to ensure they are ints using the Number.isInteger(). If the inputs are numbers the generateNumbers function is called and passed to start and end values, if the inputs are not ints then a Sweet Alert error message is thrown.
function generateNumbers()
This function creates an empty array and then uses a for loop to generate a sequence of numbers starting from the start value and ending at the end value. Each number is added to the array using the push() method, and the resulting array is returned to the calling function.
function displayNumbers()
This function takes the array of numbers generated by generateNumbers() and creates an HTML table to display them. The function starts by getting the element with an id of "results" on the page and storing it in a variable. It then uses a for loop to iterate through each number in the array, classifies each number as odd or even using a conditional statement, and then creates an HTML table cell (td) with a class name of either "even" or "odd". If the index of the number is divisible by 5, the function creates a new HTML table row (tr). The resulting HTML is stored in a variable, and finally, the HTML for the entire table is inserted into the "results" element using the innerHTML property.