function getNumbers(){
//Pull numbers and make them integers.
let num1 = parseInt(document.getElementById("num1").value);
let num2 = parseInt(document.getElementById("num2").value);
let end = parseInt(document.getElementById("end").value);
//Verify numbers are integers.
//Verify first and second numbers aren't larger than 10.
//Verify ending value isn't greater than 1000.
if(!Number.isInteger(num1) || !Number.isInteger(num2) || !Number.isInteger(end)){
alert("Only enter numbers!");
return;
} else if (num1 > 10 || num2 > 10){
alert("Only enter values less then 10.");
return;
} else if (end > 1000){
alert("Ending number must be below 1000.");
return;
}
//Generate an array and save to 'numbers'.
let numbers = generateNumbers(1, end);
//Display our array.
displayValues(numbers);
//Create an array, start at 1 end at end number.
function generateNumbers(start, end){
let numbers = [];
for (let i = start; i <= end; i++) {
numbers.push(i);
}
return numbers;
}
//Set results div inner html to nothing.
//for each element verify multiples, assign classes and innerHTML.
//appendChild div with newly created col.
function displayValues(numbers){
results.innerHTML = "";
numbers.forEach(element => {
let div = document.createElement("div");
div.classList.add("col","border","border-dark", "p-2");
if(element % num1 === 0 && element % num2 === 0){
div.classList.add("fizzbuzz", "bg-warning");
div.innerHTML = ("FizzBuzz");
} else if (element % num1 === 0){
div.classList.add("fizz", "bg-secondary");
div.innerHTML = ("Fizz");
} else if (element % num2 === 0){
div.classList.add("buzz", "bg-dark");
div.innerHTML = ("Buzz");
} else {
div.innerHTML = element;
div.classList.add("bg-light");
}
document.getElementById("results").appendChild(div);
});
}
}