Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Last active August 29, 2015 14:22
Show Gist options
  • Save greggnakamura/14420a7581e0c59adb6b to your computer and use it in GitHub Desktop.
Save greggnakamura/14420a7581e0c59adb6b to your computer and use it in GitHub Desktop.
Javascript: Number of prime numbers under 100 (HackerRank)
// variables
var number = 2,
count = 0;
// while prime count
while (number < 100) {
if (isPrime(number)) {
count++;
}
number++;
}
// check if number is a prime number
function isPrime (number) {
for (var i = 2; i < number; i++) {
if(number % i === 0)
return false;
}
return true;
}
// output
console.log(count); // 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment