Created
November 11, 2014 04:33
-
-
Save sfasano/f8cc0cfd424d69e7c7fa to your computer and use it in GitHub Desktop.
My Prime Guessing Game
This file contains hidden or 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
<html> | |
<script> | |
var guess; | |
var prime = 2; | |
var isPrime = function(prime) { | |
for (var count = 2; count < prime; count++){ | |
if (prime % count == 0){ | |
return false; | |
} | |
} | |
return true; | |
} | |
var nextPrime = function(prime) { | |
do { | |
prime++; | |
} while (!isPrime(prime)) | |
return prime; | |
} | |
guess = prompt("What's the first prime number?"); | |
while (guess == prime) { | |
guess = prompt("What's the next prime number?"); | |
prime = nextPrime(prime); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment