Get Prime Numbers From Number Range

// List the prime numbers between two inputs // Live demo: http://jsbin.com/oqasir/4/ function isPrime(x) { if(x > 1) { for(y = x-1; y > 1; y--) { if(y === x || x % y === 0) { return false; } } return true; } else { return false; } } function showPrimes(start, end) { while(end > start) { if(isPrime(start) === true) { console.log(start); } start++; } }
Input two numbers and get the prime numbers in between them.

Alternately you can test a single number.

Demo: http://jsbin.com/oqasir/4/

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.