Hi am am doing a bit of research and came up with a little game to demonstrate my website to school kids.
My idea is that they type in a number in a text box and then they click a button to see if their guess matches the random number. If their guess is too low they get a window.prompt saying the no. is too low please enter another. If this guess is too low or high they get the same kind of window.
I have made an attempt at the code but for some reason it doesnt work. I'd like to keep the code relatively simple (if possible) so that I can explain it to them.
Is there any way someone might be able to help me please as i'm new at this game and pretty overwhelmed!!!
Thanks in advance
Arun
The guess is entered in a simple text box in a form named 'form' and the action button then calls this function.
function random(){
var temp;
var randGuess;
var random;
var randomInt;
var at1;
var at2;
at1 = window.prompt("Your guess is too low, please enter another guess","0");
at2 = window.prompt("Your guess is too high, please enter another guess","0");
random = math.floor(math.random()*11);
randomInt = parseInt(random);
randGuess = parseInt(document.form.randomNo.value);
if(randGuess=randomInt){window.alert("Congratulations, you have guessed the random number correctly!!!")}
if(temp=randomInt){window.alert("Congratulations, you have guessed the random number correctly!!!")}
if(randGuess>randomInt) {temp = at2;}
else{ if(randGuess<randomInt) {temp = at1;}
else window.alert("Correct!!");
}
}