The Code for FIZZBUZZ
The Code is structured as follows.
getValues
getValues is a function that uses DOM manipulation methods, such as getElementById to retrieve user input for fizz value and buzz value. Then numbers array is declared to store values between 1 and 100.
parseInt
parseInt validates the input type, if any value entered is not of integer data type it is automatically converted to an integer.
If Else
The if statement validates that both fizz value and buzz value are numbers.
Then fizzBuzz and displayData functions are called.
Furthermore, the user is alerted to only enter integers as input.
fizzBuzz
fizzBuzz function receives fizz value and buzz value as parameters. In a for loop, each number between 1 and 100 is then checked if divisible it is divisible by 3, 5 or both and replaced by 'Fizz', 'Buzz' and 'FizzBuzz' respectively. Then numbers array is returned.
displayData
displayData function displays all numbers from 1 to 100. Each row of the table is divided into 5 columns by incrementing the loop with 5 (line 47).
Table data or content from fizzbuzzTemplate is imported into tableRow using rowCols variable. Different font colors are added to each cell in table based on the predefined CSS class using classList (lines 51 to 64).
All the data generated is appended to the table rows (line 66).