PDA

View Full Version : 3 guess number page

crazyeyez51
08-18-2007, 10:29 PM
I need help with a program Im trying to write. This program is a three guess program, guessing numbers between 1-10 having three guesses and telling you higher or lewer then after the third time says sorry the correct answer is (num) I have this so far

<html>
<head>
<title>Guess Number Three Times</title>
<script language ="Javascript">
<!--
function makeGuess(num)
{var guess = parseInt(prompt('Guess number from 1 to 10',' '));
if(guess == num) alert('Correct!');
esle (guess < num) alert('The number is more than' + num);
esle if (guess > num) alert('The number is less than' + num);
esle alert('Sorry wrong guess it was' + num);
}//end makeGuess
//-->
</script>
</head>
<body>
<center>
<h1>Guess The Right Number</h1>
<h2>Welcome to the guessing game!</h2>
<h3>Guess a Number between 1 and 10</h3>
</center>
<script language = "javascript">
<!--
var num = (Math.floor(Math.random()*10))+1;//rolldice
//-->
</script>

<center>
<input type="button"
value="Make a Guess"
onClick="makeGuess(num)">
</center>

</body>
</html>

Philip M
08-19-2007, 10:50 AM
My guess is that you cannot spell "else".

<html>
<head>
<title>Guess Number Three Times</title>
<script language ="Javascript">
<!--
function makeGuess() {

var num = (Math.floor(Math.random()*10))+1;//rolldice

for (var i = 1; i<=3; i++) {
var guess = parseInt(prompt('Guess number from 1 to 10',' '));

if (guess <1 || guess >10) {
alert ("Not a valid number - retry!");
guess = 0;
i--;
}

if(guess == num) {
alert('Correct! The number was ' + num);
i = 4; // = break
}

if (i < 3 && guess != 0 && guess < num) {
alert('The number is more than ' + guess);
}

if (i < 3 && guess > num) {
alert('The number is less than ' + guess);
}

}

if (guess != num) {
alert('Sorry, wrong guess! It was ' + num);
}
}
//-->
</script>

</head>
<body>

<center>
<h1>Guess The Right Number</h1>
<h2>Welcome to the guessing game!</h2>
<h3>Guess a Number between 1 and 10</h3>
<input type="button" value="Make a Guess" onClick="makeGuess()">
</center>

</body>
</html>