Task

Write a game (computer program) that follows the following rules:

 The computer chooses a number between given set limits.
 The player is asked for repeated guesses until the the target number is guessed correctly
 At each guess, the computer responds with whether the guess is:
 higher than the target,
 equal to the target, 
 less than the target,   or
 the input was inappropriate. 


Related task

   Guess the number/With Feedback (Player)


 
;;(read <default-value> <prompt>) prompts the user with a default value using the browser dialog box.
;; we play sounds to make this look like an arcade game
(lib 'web) ; (play-sound) is defined in web.lib
 
(define (guess-feed (msg " 🔮 Enter a number in [0...100], -1 to stop.") (n (random 100)) (user 0))
   (set! user (read user msg))
   (play-sound 'ko)
   (unless (eq? n user ) ; user is the last user answer
       (guess-feed 
               (cond ;; adapt prompt according to condition
                    ((not (integer? user)) "❌ Please, enter an integer")
                    (( < user 0) (error "🌵 - It was:" n)) ; exit to top level
                    ((> n user) "Too low ...")
                    ((< n user) "Too high ..."))
              n user))
    (play-sound 'ok )  
    " 🔮 Well played!!  🍒 🍇 🍓")
 