The Code for Ciento
// Retrieve input values from the web page and call other functions
function getValues() {
// Retrieve start and end values from web page
let startValue = document.getElementById("startValue").value;
let endValue = document.getElementById("endValue").value;
// Validate input as integers
startValue = parseInt(startValue);
endValue = parseInt(endValue);
if (Number.isInteger(startValue) && Number.isInteger(endValue)) {
// Generate array of numbers between start and end values
let numbers = generateNumbers(startValue, endValue);
// Display generated numbers on web page
displayNumbers(numbers);
}
else {
// Display an alert if input values are not integers
alert("You must enter integers!");
}
}
// Generate array of numbers between start and end values
function generateNumbers(startValue, endValue) {
let numbers = [];
// Generate numbers between start and end values and add them to the array
for (let i = startValue; i <= endValue; i++) {
numbers.push(i);
}
return numbers;
}
// Display the generated numbers on the web page, with even numbers marked in bold
function displayNumbers(numbers) {
let tableRows = "";
// Loop through each number in the array and add it to the table as a row
for (let i = 0; i < numbers.length; i++) {
let number = numbers[i];
let rowClass = "";
if (number % 2 === 0) {
// If number is even, mark the row as bold
rowClass = "even";
}
// Add the number to the table as a row
tableRows += `${number} `;
}
// Display the table on the web page
document.getElementById("results").innerHTML = tableRows;
}
Function: getValues()
This function retrieves the start and end values from the web page and calls the generateNumbers() and displayNumbers() functions. It validates that the inputs are integers and displays an alert if the inputs are invalid.
Function: generateNumbers(sValue, eValue)
This function generates an array of numbers between 0 and 100, inclusive, with a given starting and ending value.
Function: displayNumbers(numbers)
This function displays the generated numbers on the web page, with even numbers marked in bold.
Overall, this code retrieves the start and end values from the web page, generates an array of numbers between 0 and 100 with even numbers marked in bold, and then displays those numbers on the web page.