View Full Version : Resolved Guessing Game Help.

12-14-2011, 09:22 PM
What I'm trying to achieve is it initialises a number between 1-2000 randomly.
When the submit button is clicked it simply returns if the number that is in putted is higher or lower than the randomly initialised number.
External JavaScript:


<script type="text/javascript" src="jsscri.js"></script>
<body onload="initialisation ()">

<form name="exampleform">
Number: <input name="number" type="text"
onchange='checkNumber( this.value );'>
<input name="submit" type="button" value="Guess"
onclick= 'checkValue()';/>


If you load this onto a webpage you'll see what i'm trying to do. I tried deleting the rest of the code to keep the size of the code down.

12-14-2011, 09:34 PM
"checkNumber" is not a function. Did you leave some code out?

Also, you misspelled initialization as "initialisation" in the onload.

Old Pedant
12-14-2011, 09:41 PM
Also, the checkValue( ) function requires a single argument passed to it.

When invoked from the "Guess" button, no value is supplied.

12-14-2011, 09:42 PM
Sorry. I changed the spelling. Heres the check function. It checks the in-putted text and alerts the user if the number they put is outside the range of 0-2000.

function checkNumber(num)

if ( isNaN(num) || num < 0 || num > 2000) {
alert( num + " Number has to be between 0 - 2000");

Also, the checkValue( ) function requires a single argument passed to it.

<input name="submit" type="button" value="Guess"
onclick= 'checkValue(num)';/>

Is this right? I'm not sure if it looks at the values in the input box then checks.

Old Pedant
12-14-2011, 10:13 PM
How could num possibly be right?

Look here:

<input name="number" ...


<input name="submit" type="button" value="Guess"
onclick="checkValue(this.form.number.value)" />