Code to display all prime numbers not working in JavaScript? -



Code to display all prime numbers not working in JavaScript? -

i'm trying display prime numbers 10 , isn't working. can see did wrong?

function findprimenumbers() { var count = 10, primes = []; (var = 0; <= count; i++) { if (count / === 1 || count) primes.push(i); else continue; count -= 1; } (var = 0, len = primes.length; < len; i++) homecoming primes[i]; } console.log(findprimenumbers());

it returns 0 in console.

for (var = 0, len = primes.length; < len; i++) homecoming primes[i];

here homecoming first element of array. think meant this

var retstr = ""; (var = 0, len = primes.length; < len; i++) { //to improve str format if(i == len-1) retstr += primes[i]; else retstr += primes[i] + ", "; } homecoming retstr;

hope helps.

javascript primes

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -