New to JS. I'm trying to change my for loop to a while loop. It prints the factors of a number, but for some reason, the while loops causes the webpage to stop responding. Any help is appreciated.
var num, i = 1,
array = [];
num = parseInt(prompt("Please enter a number:"));
while (i < num) {
if (num % i == 0) {
array.push(i);
i++;
}
}
alert("The factors of " + num + " are: " + array + " and " + num);
numa value if the prompt did not return a numeric value or not a value at all, you might end up withNaNwhich would also fall into the case ofi < numreturningfalse