Write a JavaScript program that reads three integers named start, end, and divis
ID: 3726960 • Letter: W
Question
Write a JavaScript program that reads three integers named start, end, and divisor from three textfields. Your program must output to a div all the integers between start and end, inclusive, that are evenly divisible by divisor. The output integers must be separated by spaces. For example, if a user entered 17, 30, and 5, your program would output "20 25 30" (without the quotes) because those are the only integers between 17 and 30 (including 17 and 30) that are evenly divisible by 5.
DO NOT SUBMIT CODE THAT CONTAINS AN INFINITE LOOP. If you try to submit code that contains an infinite loop, your browser will freeze and will not submit your exam to I-Learn.
If you wish, you may use the following HTML code to begin your program.
Explanation / Answer
<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Title</title>
<script type="text/javascript">
/* Input:
* Processing:
* Output:
*/
function multiples() {
var start = Number(document.getElementById("start").value);
var end = Number(document.getElementById("end").value);
var divisor = Number(document.getElementById("divisor").value);
var result = "";
var i;
for (i = start; i <= end; i++) {
if(i%divisor==0)
{
result += i + " ";
}
}
document.getElementById("output").innerHTML = result.toString();
}
</script>
</head>
<body>
<p id="demo"></p>
Start: <input type="text" id="start" size="5"><br>
End: <input type="text" id="end" size="5"><br>
Divisor: <input type="text" id="divisor" size="5"><br>
<button type="button">Click</button>
<div id="output"></div>
</body>
</html>
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.