on mouseUp
put random(19) into theNumber
put 0 into botNum
put 20 into topNum
put 0 into numberOfTrys
put "I am thinking of a number between 0 and 20." & return & ¬
"Try to guess the number:" into sayIt
repeat
add 1 to numberOfTrys
ask sayIt
if the result is "Cancel" OR it is empty then exit repeat
put it into theGuess
if theGuess = theNumber then
answer "You got it! The number is" && theGuess & "." & return &¬
"You guessed in" && numberOfTrys && "attempts."
exit repeat
else if theGuess is not a number then
put theGuess && "is not a number." into sayIt
else if theGuess > topNum then
put theGuess && "is greater than" && topNum & "." into sayIt
else if theGuess < botNum then
put theGuess && "is less than" && botNum & "." into sayIt
else if theGuess < theNumber then
put "The number is greater than" && theGuess & "." into sayIt
put theGuess into botNum
else if theGuess > theNumber then
put "The number is less than" && theGuess & "." into sayIt
put theGuess into topNum
end if
put return & "Please enter a number between" && botNum &&¬
"and" && topNum & ":" after sayIt
end repeat
end mouseUp