Created
November 21, 2016 01:15
-
-
Save Temmyhlee/187e89366fe5222914ba6d737a308c59 to your computer and use it in GitHub Desktop.
Colour 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
<!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