I'm working on an HTML coding exercise. The HTML file will let the users input a starting number, an ending number, and a step number. Then output all the even numbers between the starting number and the ending number by the step size after clicking a button. But so far nothing displays after the button is clicked. Also, I tried to insert text into the paragraph using span tags but that doesn't work. Please help. Thank you.
function validateItems(){
var starting = document.forms["displayEvens"]["starting"].value;
var ending = document.forms["displayEvens"]["ending"].value;
var step = document.forms["displayEvens"]["step"].value;
var numbers = "";
var adding = starting;
if (starting == "" || isNaN(starting)){
alert("Starting Number must be filled with a number");
document.forms["displayEvens"]["starting"].focus();
return false;
}
if (ending == "" || isNaN(ending) || ending <= starting){
alert("Ending Number must be filled with a number or must be greater than the starting number");
document.forms["displayEvens"]["ending"].focus();
return false;
}
if (step == "" || isNaN(step) || step < 0){
alert("Step Number must be filled with a number and must be positive");
document.forms["displayEvens"]["step"].focus();
return false;
}
while (adding < ending){
adding = adding + step;
if (adding % 2 == 0){
numbers = String(adding) + " ";
}
}
document.getElementById("first").innerText = starting;
document.getElementById("second").innerText = second;
document.getElementById("middle").innerText = step;
document.getElementById("numbers").innerText = numbers;
return false;
}
<!DOCTYPE html>
<html>
<head>
<script type="text/JavaScript" src="displayEvens.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<h1>Display Evens</h1>
<form name="displayEvens" onsubmit="return validateItems();">
<div class="form-group">
<label for="starting">Starting Number</label>
<input type="number" class="form-control" id="starting">
</div>
<div class="form-group">
<label for="ending">Ending Number</label>
<input type="number" class="form-control" id="ending">
</div>
<div class="form-group">
<label for="step">Step</label>
<input type="number" class="form-control" id="step">
</div>
<button type="submit" class="btn btn-default">Display Evens</button>
</form>
<p>Here are the even numbers between <span id="first"></span> and <span id="second"></span> by <span id="middle"></span>'s:</p><br />
<p><span id="results"></span></p>
</div>
</body>
</html>