Last active
August 29, 2015 14:22
-
-
Save greggnakamura/14420a7581e0c59adb6b to your computer and use it in GitHub Desktop.
Javascript: Number of prime numbers under 100 (HackerRank)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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