I am currently trying to get my program to work. It is supposed to factor numbers from a low to high bound. In other words, if the low bound is 12, and the high bound is 16, it should output the following into a tag....
12: 2,3,4,6,12
13: 13
14: 2,7,14
15: 3,5,15
etc.....
However, I am getting the output like this:
12: 2,3,4,6,12,
13,
2,7,14,
3,5,15,
2,4,8,16,
17,
it is outputting in a strange manner, and I keep trying to move it around. The only line that is correct is the top one. Can anyone here give me a hand? I am sure it's something minor, but I just can't get it......
function calculate(num){
var int = 2;
var num = document.getElementById("num").value;
var high = document.getElementById("high").value;
var str = num + ": ";
while (num <= high){
for (var i = 2; i <= num; i++){
if(num % i == 0){
str += i + ",";
}
}
num++;
str += "\n";
}
document.getElementById("outputArea").innerHTML = str;
}