asharm27
03-15-2005, 02:43 PM
Hi
I am currently working on a webpage that has a javascript element to analyse the input in a text box.
I have a series of numbers in a table and the user needs to complete the series by entering their guess for the next number.
There is then a submit button that they press to see if they are correct.
If: The guess is too high i want it to display a window.alert saying that "the guess is too high, try again"
If: The guess is too low i want it to display a window.alert saying "the guess is too high, try again"
Else: A window alert saying "Correct!"
Problem is I only want it to allow 5 guesses i was thinking of using the do/while function.
Is this possible?
here is my attempt:
var loop = 0;
function numberGuess(TheNumber,TheGuess)
{
if(loop = 10)
{
window.alert("The number is" + TheNumber)
}
else
{
if (TheGuess > TheNumber)
{
window.alert("Too Big");
}
else if(TheNumber > TheGuess)
{
window.alert("Too Small");
}
else
{
window.alert("CORRECT");
}
}
loop += 1;
Any suggestions will be greatly appreciated! :)
thanks
Arun
I am currently working on a webpage that has a javascript element to analyse the input in a text box.
I have a series of numbers in a table and the user needs to complete the series by entering their guess for the next number.
There is then a submit button that they press to see if they are correct.
If: The guess is too high i want it to display a window.alert saying that "the guess is too high, try again"
If: The guess is too low i want it to display a window.alert saying "the guess is too high, try again"
Else: A window alert saying "Correct!"
Problem is I only want it to allow 5 guesses i was thinking of using the do/while function.
Is this possible?
here is my attempt:
var loop = 0;
function numberGuess(TheNumber,TheGuess)
{
if(loop = 10)
{
window.alert("The number is" + TheNumber)
}
else
{
if (TheGuess > TheNumber)
{
window.alert("Too Big");
}
else if(TheNumber > TheGuess)
{
window.alert("Too Small");
}
else
{
window.alert("CORRECT");
}
}
loop += 1;
Any suggestions will be greatly appreciated! :)
thanks
Arun