<%!
int nbr = ((int)(Math.random()*100.0))+1;
int cnt = 0;
%>

<html>
<head>
</head>
<body>

<%
if (cnt==0) {
%>

<h1>I am thinking of a number between 1 and 100</h2>
<h2>Guess which!</h2>
<form method="get">
What is your guess? <input type="text" name="guess" size="5">
<input type="submit" value="Guess!">
</form>

<%
  cnt++;

} else {
  int guess = Integer.parseInt(request.getParameter("guess"));
  if (guess==nbr) {
%>

<h1>Congratulations, that was correct!</h1>
<h3>You guessed <%= cnt %> times.</h3>
<h3><a href="guessinggame.jsp">Click here for another try!</a></h3>

<%
    cnt = 0;
    nbr = ((int)(Math.random()*100.0))+1;
  } else {
    if (guess<nbr) {
%>

<h1>Too low!</h1>

<%
    } else {
%>

<h1>Too high!</h1>

<%
    }
%>

<h2>Try again!</h2>
<form method="get">
What is your guess? <input type="text" name="guess" size="5">
<input type="submit" value="Guess!">
</form>

<%
    cnt++;

  }
}
%>

</body>
</html>