3. Program Flow
Activity 3.01: Number-Guessing Game
Solution
- Create a Ruby source file called
hilow.rb
. - Create the basic program architecture that allows a user to choose to play or exit:
play_choice = 'y' while play_choice == 'y' puts "Welcome to HiLow - Shall we play" play_choice = gets.chomp.downcase if play_choice == 'y' play_game end end puts "Thanks for playing!"
- Implement a single
guess
method that will employ various conditions for guessing a number. It will suggest that the player guesses lower/higher if the guess is incorrect:def try_guess(magic_number, guess) if guess == magic_number puts "You guess correctly!" return true elsif guess < magic_number puts "Guess higher" return false ...