Skip to content

Instantly share code, notes, and snippets.

@samrat
Created September 17, 2011 04:18
Show Gist options
  • Save samrat/1223620 to your computer and use it in GitHub Desktop.
Save samrat/1223620 to your computer and use it in GitHub Desktop.
guess the number game
<html>
<body>
<form name="guess">
<input type="text" name="num">
<input type="button" onclick="checkGuess()" value="Submit">
</form>
<script type="text/javascript">
var answer = Math.floor(Math.random()*11);
//document.write(answer);
function checkGuess(){
value = document.forms[0].elements[0].value;
if (value == answer){document.write("Correct");}
else if (answer-2 < value < answer+2){document.write("Close!!")}
else {document.write("Incorrect");}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment