Higher or Lower

[Total: 0    Average: 0/5]

You can try to guess the secret number.

Head Code:

<script>
   <!-- Hide from old browsers
    var RNumber;
    var RTries;
    limit = 50;

    function Random() {
      today = new Date();
      num = today.getTime();
      num = Math.round(Math.abs(Math.sin(num) * 1000000)) % limit;
      return num;
    }

    function Init(){
      RNumber = Random();
      RTries = 0;
      document.FGame.Output.value='I am thinking of a number between 0 and ' + (limit-1) +' Guess it....';
      document.FGame.Tries.value=RTries;
      document.FGame.HighLow.value='';
      document.FGame.Input.value='';
    }

    function Game(Number) {
      if(Number==RNumber) {
        RTries++;
        document.FGame.Output.value='You guessed it in ' + RTries + ' tries! It was ' + RNumber + '! Hit Init to go again';
        document.FGame.HighLow.value='Got It!';
      } 
      else {
        RTries++;
        document.FGame.Output.value='Nope, ' + Number + ' is not the number I am thinking about!';
        document.FGame.HighLow.value=(RNumber > Number) ? 'Higher!' : 'Lower!';
        document.FGame.Tries.value=RTries;
      }
    }
   // Unhide -->
  </script>

Body Code:

<p align="center">A little game: Guess my number<br></p>
<hr align="center">
<p>This is a little game using javascript, after hitting the init button, the computer
thinks of a random number between 0 and 49. You can type the number with the keypad and
try it with the Try It! button. The computer will tell you if you got to guess higher or
lower. It's really simple!<br>
</p>
<form NAME="FGame">
  <p><input TYPE="txt" NAME="Output" VALUE Size="50"><br>
  <input TYPE="txt" NAME="Input" VALUE Size="10"> The number is: <input TYPE="txt"
  NAME="HighLow" VALUE Size="10"> You tried: <input TYPE="txt" NAME="Tries" VALUE="0"
  SIZE="2"> Times.<br>
  <input TYPE="button" NAME="one" VALUE="  1  " OnClick="FGame.Input.value += 1"> <input
  TYPE="button" NAME="one" VALUE="  2  " OnClick="FGame.Input.value += 2"> <input
  TYPE="button" NAME="one" VALUE="  3  " OnClick="FGame.Input.value += 3"><br>
  <input TYPE="button" NAME="one" VALUE="  4  " OnClick="FGame.Input.value += 4"> <input
  TYPE="button" NAME="one" VALUE="  5  " OnClick="FGame.Input.value += 5"> <input
  TYPE="button" NAME="one" VALUE="  6  " OnClick="FGame.Input.value += 6"><br>
  <input TYPE="button" NAME="one" VALUE="  7  " OnClick="FGame.Input.value += 7"> <input
  TYPE="button" NAME="one" VALUE="  8  " OnClick="FGame.Input.value += 8"> <input
  TYPE="button" NAME="one" VALUE="  9  " OnClick="FGame.Input.value += 9"><br>
  <input TYPE="button" NAME="one" VALUE="  0  " OnClick="FGame.Input.value += 0"> <input
  TYPE="button" NAME="DoIt" VALUE=" Try it!  "
  OnClick="Game(FGame.Input.value); FGame.Input.value=''"><br>
  <input TYPE="button" NAME="init" VALUE="        Init       " OnClick="Init()"> </p>
</form>

Times Viewed: 16

Leave a Reply

Your email address will not be published. Required fields are marked *