<html>
<head>
<title>NumberGuesser</title>
<script>
//NumberGusser
//Chao Li. October 10, 2007.
//the classic number guessing game
var guess = 50;
var target = 0;
var turns = 0;
var msg = "";
target = Math.floor(Math.random() * 100) + 1;
// alert (target);
msg = "I'm think of a number between 1 and 100. \n";
msg += "Guess my number, and I'll tell you if it's too high, \n";
msg += "too low, or correct. Try to geuss in the fewest turns.";
alert (msg);
guess = eval (prompt("What is your guess?", guess));
while (guess != target){
turns++;
if (guess > target)
{
guess = eval (prompt (turns +". Too high!! Next guess?", guess));
}// end if
if (guess < target)
{
guess = eval (prompt (turns +". Too low!! Next guess?", guess));
}// end if
if (guess == target)
{
msg = "you win!!! \n";
msg += "it too you ";
msg += turns + " turns! ";
alert (msg);
}//end if
}// end while
</script>
</head>
</html>