PDA

View Full Version : help with random number guessing...

disneyfan
03-07-2005, 06:16 PM
what do I need to do to get this simple guess the sum of 2 random numbers generated exercise?

<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function randNum() {
var randomNumber1 = random(10);
var randomNumber2 = Math.random(10);
}

function verifyGuess() {
if (guessNum = sumNum)
else
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>

<body>

<p>
<input type="text" name="txtNum1" size="20">
<input type="text" name="txtNum2" size="20">
<input type="text" name="txtGuess" size="20">
<input type="submit" value="New Problem" name="button1" onclick=randNum()>
<input type="reset" value="Verify" name="button2" onclick=verifyGuess()>
</p>
</form>

vwphillips
03-07-2005, 08:27 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<title></title>

<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
// use indenting to aid readability
// and do not use abreviated code until you are ready

// declare variables
var randomNumber1;
var randomNumber2;
var sumNum;
var guessNum;

function randNum() {
document.getElementById('InPut').style.visibility='visible';
// The pseudorandom number generated is from 0 (inclusive) to 1 (exclusive),
// that is, the returned number can be zero, but it will always be less than one.
// The random number generator is seeded automatically when JScript is first loaded.
randomNumber1 = Math.random()*10;
randomNumber2 = Math.random()*10;
}

function verifyGuess() {
// check that the guess is a number
return;
}
document.getElementById('InPut').style.visibility='hidden';
// the textbox field is a string not digits so convert to digits I am using parseInt so only whole numbers used
// == exact comparison, = make equal to
if (guessNum == sumNum){
}
else {
}
}

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</SCRIPT>

<body>