Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: 3 guess number page

1. ## 3 guess number page

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>
<title>Guess Number Three Times</title>
<script language ="Javascript">
<!--
function makeGuess(num)
{var guess = parseInt(prompt('Guess number from 1 to 10',' '));
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>
<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>

• My guess is that you cannot spell "else".

Code:
```<html>
<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>

<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>```

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•