Skip to content

Instantly share code, notes, and snippets.

@Temmyhlee
Created November 21, 2016 01:15
Show Gist options
  • Save Temmyhlee/187e89366fe5222914ba6d737a308c59 to your computer and use it in GitHub Desktop.
Save Temmyhlee/187e89366fe5222914ba6d737a308c59 to your computer and use it in GitHub Desktop.
Colour Guessing Game
<!DOCTYPE html>
<html>
<head>
<title>Colour Guessing game</title>
</head>
<body onload="do_game()">
<script type="text/javascript">
var colors = [];
var target;
var guess_input;
var guesses = 0;
colors = ["red","blue","purple", "cyan", "yellow", "black", "deeppink", "forestgreen", "pink", "salmon", "royalblue", "green", "aqua"];
colors.sort();
function do_game() {
var random_number = Math.floor(Math.random() * colors.length) + 1;
target = colors[random_number];
alert(target);
while (guess_input !== target){
guess_input = prompt("I am thinking of one of these colors:\n\n" + colors.join(", ") + "\n\n" + "What color am I thinking of?")
guesses++;
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment