Home > Games & Entertainment > Guess-A-Number


Guess-A-Number

December 31st, 2009
Play the JavaScript version of Guess-A-Number. First, select a number range and then try to guess the number the computer has chosen.


Range of numbers
From:

To:

he JavaScript Source: Games: Guess-A-Number Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!

<!– THREE STEPS TO INSTALL GUESS-A-NUMBER:

1.  Paste the coding into the HEAD of your HTML document
2.  Add the onLoad and unonLoad event handlers to the BODY tag
3.  Put the last coding into the BODY of your HTML document  –>

<!– STEP ONE: Copy this code into the HEAD of your HTML document  –>

<HEAD>

<SCRIPT LANGUAGE=”JavaScript”>

<!– This script and many more are available free online at –>
<!– The JavaScript Source!! http://javascript.internet.com –>

<!– Begin
var my_no,count;
function load() {
window.defaultStatus=”JavaScript Guess-a-Number Game”;
document.game.help.value=”Please set range of numbers and press the Start button.”;
document.game.from.focus(); }
function rnd(scale) {
var dd=new Date();
return((Math.round(Math.abs(Math.sin(dd.getTime()))*8.71*scale)%scale)); }
function range() {
var to=1+1*document.game.to.value;
count=0;
my_no=rnd(to);
while(my_no<document.game.from.value) {
my_no=rnd(to); }
document.game.help.value=”Please guess a number, enter it, and press Guess.”; }
function guess() {
var no=document.game.number.value;
count++;
if(no<my_no) document.game.help.value=”My number is greater than “+no+”.”;
else if(no>my_no) document.game.help.value=”My number is less than “+no+”.”;
else alert(“It takes you “+count+” attempts to guess this number”); }
// End –>
</SCRIPT>

<!– STEP TWO: Add the onLoad and unonLoad event handlers to the BODY tag  –>

<BODY onLoad=”load()”>

<!– STEP THREE: Copy this code into the BODY of your HTML document  –>

<CENTER>
<FORM name=game>
<TABLE border=3>
<TR>
<TD align=center colspan=2>Range of numbers</TD>
<TD align=center rowspan=2><input type=button value=” Start ” onclick=”range()”></TD>
</TR>
<TR>
<TD align=center>From:<br><input type=text name=from size=10></TD>
<TD align=center>To:<br><input type=text name=to size=10></TD>
</TD>
<TR>
<TD></TD>
</TR>
<TR>
<TD align=center colspan=3><input type=text name=help size=70></TD>
</TR>
<TR>
<TD></TD>
</TR>
<tr><td align=right colspan=3><input type=text name=number size=10><input type=button value=” Guess ” onclick=”guess()”></TD>
</TR>
</TABLE>
</FORM>
</CENTER>

<p><center>
<font face=”arial, helvetica” size=”-2″>Free JavaScripts provided<br>
by <a href=”http://javascriptsource.com”>The JavaScript Source</a></font>
</center><p>

<!– Script Size:  2.16 KB  –>

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Diigo
  • DZone
  • Fark
  • Faves
  • laaik.it
  • LinkedIn
  • Live
  • MisterWong
  • MySpace
  • Netvibes
  • Netvouz
  • NewsVine
  • Propeller
  • Reddit
  • Slashdot
  • Socialogs
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Buzz


Author: admin Categories: Games & Entertainment Tags:
Comments are closed.