<html> <body> <script> var low= prompt (\"Enter the lowbound number\"); var high
ID: 3592660 • Letter: #
Question
<html>
<body>
<script>
var low= prompt ("Enter the lowbound number");
var high= prompt ("Enter the highbound number");
function test(low, high)
{
for(var i=low;i<=high;i++)
{
var list=new Array();
list=factors(i);
document.write(i + ":"+list+"<br>");
}
}
function factors(n)
{
var num_factors = new Array();
for (var i = 2; i <=n; i++){
if (n % i === 0)
{
num_factors.push(i);
}
} return num_factors;
}
</script>
</body>
</html>
cant get the code to work, want to output this to html, example if i put lowbound 1 and highbound 10 it would output
2:2
3:3
4:2,4
5:5
6:2,4,8
7:7
8:2,4,8
9:3,9
10:2,5,10
Explanation / Answer
<html>
<body>
<script>
var low= prompt ("Enter the lowbound number");
var high= prompt ("Enter the highbound number");
test(low,high)
function test(low, high)
{
for(var i=low;i<=high;i++)
{
var list=new Array();
list=factors(i);
document.write(i + ":"+list+"<br>");
}
}
function factors(n)
{
var num_factors = new Array();
for (var i = 2; i <=n; i++){
if (n % i === 0)
{
num_factors.push(i);
}
} return num_factors;
}
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.