Exercise: Counting to 21
Make a fun game that requires the user to interact with the command-line interface.
We'll cover the following...
Counting to 21
Make a game with the following rules: You and the computer each take turns counting to 21, where each player increasing the number by either 1 or 2. Whoever says 21 loses.
You and me take turns say a number, the player forced to say '21' loses. At each turn, player can increase the number 1 or 2.Do you want to go first? (y/n) yYou (1 or 2): 2Me: 3You (4 or 5): 4Me: 5You (6 or 7): 6Me: 8You (9 or 10): 10Me: 11You (12 or 13): 12Me: 14You (15 or 16): 16Me: 17You (18 or 19): 18Me: 20You (21 :-( ): 21
Demo of the "Counting to 21" game
Hints
Ruby’s modulo operator
%
returns the remainder of a number ...