Thanks for the answer.But the way i want it to be is a bit more complicated, something like that ->a=Math.floor((Math.random())*100+1);function test1(){document.getElementById("Random number").innerHTML=a;var x=document.getElementById("test").value;if (a==x) { confirm("Gratz, you've entered the right number"); } else if (a<x) { document.getElementById("result").innerHTML="Try lower number"; }else { document.getElementById("result").innerHTML="Try higher number"; }}my goal is when 'a==x' and the confirm box appear if you press ok, the program will generate another number (if possible, if not... refresh the page ), if you press cancel, the program will exit the page and i dont know how to do it. In the attached file it works but when you enter a number even if 'a' is not equal to 'x' the program pop up this confirm box and do nothing after that.Also i've put the random method as global, because if it is inside the function every time you press Submit, it will generate new number. Correct me if im wrong.