24 Feb 20102 Number Guessing Game!

Here’s the JavaScript code for the number guessing game we did a couple of weeks ago:
[sourcecode language=”html”]
<SCRIPT LANGUAGE="javascript">
var Tries=0;
var num = Math.floor(Math.random() * 101);
function guessnum() {
var guess = document.forms[‘form1′].num.value;
if (guess == num)
alert("well done you got it right!") ;
if (guess < num)
alert("Your number is too low");
if (guess > num)
alert("Your number is too high") ;
<form name=’form1′>
Enter a number <input type=’text’ size=5 maxlength=3 name=’num’>
<input type=’button’ onClick=’guessnum();’ value=’Enter’>
Nick Grattan