I have this assignment where I have to use javascript to list the prime numbers between 1-50. While I have the code to find and list these numbers, it lists them multiple times and I can't figure out why.
anyways here is the code:
=======================
var x;
x = 1;
while(x<=50)
{
var isprime = true;
for (i = 2; i <= x / 2; i++) {
if ((x % i) == 0) {
isprime = false;
}
if (isprime == true) {
document.write(x + " is prime.<br/>");
}
}
x=x+1
}
==========================
I am bad at formatting code so I apologize for any eye bleeding. Like I said, the code partially works, but for some reason it is listing the prime numbers multiple times. Any ideas? 4 hours before this is due.![]()
XI Wiki

