The Code
The code is structured in three functions. Called functions will be detailed in their own sections.
Click a headline() to scroll to that section of the code. And click
the function name within the code to scroll to that write up section.
getValues()
This function grabs the input values from our startValue and endValue elements. It then
parses those
strings into integers. Following that, we verify the inputs are numbers as a quick check. If they
are, we call
generateNumbers() and then displayNumbers(). If they are not numbers we
use a sweet alert to call them a goof, as pirates do.
generateNumbers()
This function generates an array starting with the startValue number and counting up
until it reaches
the endValue number. It then returns numbers.
displayNumbers()
This function is used to display the numbers on the webpage for the user. First it is passed the argument of numbersarray. It grabs the id of the table where we want to display them. Then a blank string is assigned to tableHTML. Next, our for loop runs through a number of ternary and if statements to build the html.
The ternary statement value % 2 == 0 ? className = 'even' : className = 'odd' assigns
the value of 'even' if the value is divisible by 2 with 0 remainder, or 'odd' if it has a remainder.
Then we get into the if statements. If the value of i divided by 5 has a remainder of 0
then it attaches a <tr> to tableHTML. Then tableHTML adds what its current value is as a
string template literal. Following that we look into the future a bit. If the value of
i + 1 is divisble by 5 it adds a </tr> to the tableHTML.
Finally, it places the created element into the HTML and it is displayed for the user on the page.