Skip to content

Instantly share code, notes, and snippets.

@sfasano
Created November 11, 2014 04:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfasano/f8cc0cfd424d69e7c7fa to your computer and use it in GitHub Desktop.
Save sfasano/f8cc0cfd424d69e7c7fa to your computer and use it in GitHub Desktop.
My Prime Guessing Game
<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