Skip to content

Instantly share code, notes, and snippets.

@joshkh
Last active May 5, 2020 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshkh/1d469cd0e72c090159bad26540df0f47 to your computer and use it in GitHub Desktop.
Save joshkh/1d469cd0e72c090159bad26540df0f47 to your computer and use it in GitHub Desktop.
Number guessing game
(defonce secret-number (atom 0))
(defn reset-game
"Reset the secret-number atom to an integer between 0 and the highest-number"
[highest-number]
(when (reset! secret-number (rand-int (inc highest-number)))
(println (str "I am thinking of a number between 0 and " highest-number ))))
(defn guess
"Make a guess at the secret number."
[number]
(cond
(> number @secret-number) "⬇ Guess lower"
(< number @secret-number) "⬆ Guess higher"
(= number @secret-number) (str "You win! The secret number was " @secret-number)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment