Solution to Cassidoo's Week of Aug 21, 2023 Challenge
Make a "guessing game" where there is a target number, and as the user makes guesses, the output returns higher or lower until the user is correct.
I haven't messed with PHP's CLI handling of user input in a while, so I decided to stay focused on my language of 'choice'.
Went a little above the basic request, allowing users to override the min/max range. Available commands
$ php guessing-game.php
$ php guessing-game.php help
$ php guessing-game.php [min] [max]
$ php guessing-game.php [max]
Technically also works in shell more directly as well... provided you make sure it's executable, have php
located at /usr/bin/php
, and likely more situations not directly encountered today while writing this out.
$ ./guessing-game.php
$ ./guessing-game.php help
$ ./guessing-game.php [min] [max]
$ ./guessing-game.php [max]
Defaults to a random number between 1 and 100, limited to positive integers.