Games >>> Guess 1 100.
 
Script Categories













Games >>> Guess 1 100.

Another JavaScript guess-a-number game. However, this one automatically has a set range of 1 - 100.

Guessing Game

Guess the same number that the computer has guessed. The number will range from 1 to 100.

Reload the page to start a new game.
Your Guess:
#-Guesses: INFO:

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">      
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
var js_mult1=3141
var js_mult2=5821
var js_m1=100000000
var js_m2=10000
var js_iseed=0
var js_iseed1=0
var js_iseed2=0
function random() {
if (js_iseed == 0) {
now = new Date()
js_iseed = now.getHours() + now.getMinutes() * 60 + now.getSeconds() * 3600
}
js_iseed1 = js_iseed / js_m2
js_iseed2
= js_iseed % js_m2
var tmp = (((js_iseed2 * js_mult1 + js_iseed1 * js_mult2) % js_m2) *
js_m2 + (js_iseed2 * js_mult2)) % js_m1
js_iseed
= (tmp + 1) % js_m1
return (Math.floor((js_iseed/js_m1) * 100))
}
var nGuesses = 0

function GuessNum() {
var response
var num = parseInt(document.form1.guess.value)
document.form1.guess.value = num
nGuesses
++
response = ""
if (num < myNumber)    response = response + "Higher!"
if (num > myNumber)    response = response + "Lower!"
if (num == myNumber) {
respone = "Correct!";
alert ("Right!!  Reload the page to start another game....");
}
document.form2.result.value=response
document.form2.guesses.value=nGuesses
document.form1.guess.focus()
document.form1.guess.select()
return true
}
function GiveUp() {
var response
nGuesses
= 0
alert("The number was " + myNumber +".  Reload page to start a new game....");
}
function Load()
{
    document.form1.guess.focus();
    document.form1.guess.select();
}
window.onload = Load;
// End -->
</script>
<H2>Guessing Game</H2>
<
font size=2>
Guess the same number that the computer has guessed. The number will range from 1 to 100.<br><br>Reload the page to start a new game.</font>
<SCRIPT>
myNumber = random();
nGuesses = 0
</SCRIPT>
<FORM name="form1" onSubmit="GuessNum(); return false">
Your Guess: <INPUT TYPE="text" NAME="guess" SIZE=5>
<INPUT
TYPE="button" VALUE="     Guess...   " onClick="GuessNum();">
<INPUT
TYPE="button" VALUE="  GiveUp  " onClick="GiveUp();">
</FORM>
<FORM
name="form2">
#-Guesses: <INPUT TYPE="text" NAME="guesses" SIZE=3>
INFO: <INPUT TYPE="text" NAME="result" SIZE=10>
</FORM>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).




©