JavaScript Prime Number Generator

fixXxer

New Member
I'm trying to write a JavaScript prime number generator that lists every prime between 1 and 100. I know this is a common programming exercise and there's an abundance of solutions on the web. My question is why does my solution result an empty array? Here's the code:\[code\]var primeNumbers = [];for (var x=2; x<101; x++) if (x%2 === 0) { break; } else { for (var y=2; y<101; y++) { if (x/y > 1) { break; } else { primeNumbers.push(x); } } }};console.log(primeNumbers);\[/code\]
 
Back
Top