ruby - Creating while loop for boolean status of a class method -
GuessingGame with a method called a code named "code>" is .
I am creating some test codes and want to make a loop until the solution is correct:
class GuessingGame def Initialize (answer) = Answer @ Hull = false end DEF estimate (guess_num) if estimate_num < @answer@hall = false: low eelsf estimate_num & gt; @true = Hull = False: High Elsef estimation_nank = @answer @ hull == right: right end end def solve? Test code that does not work: False says, "There is a number between 1-75" estimate_nank = gets.chomp.to_i end of game.guess (guess_num)
Ruby does not like my While game.solved? Incorrect
and saying that I have the wrong number of arguments.
What am I doing wrong here?
I'm running Ruby 2.1.1p76.
At the top of your class, you need it:
class Gearganggame attr_reader: solution
from the API doctor: You Creates an instance variable and the same method which returns the value of each instance variable. From here you can: To begin the game, you just need to make a few changes to your code: The loop can be read as long as I think what you mean to say, while game.solved? Incorrect In my example, it is like saying attr_reader <
class guessinggame attr_reader: solve def initialize (answer) @answer = answer @ solved = false end def estimate (Guess_num) if estimate_num & lt; @answer@hall = false: low eelsf estimate_num & gt; @ Entry = False: High Elsef estimation_num = @answer @ hal = true: right end ending
game.solved = true
to keep looping.
was while game.solved == incorrect
. While game.solved == Incorrect
will work fine in your scenario. to game.solved
until game.solved == not true
, to execute the same thing Just two different ways to hope that helps!
Comments
Post a Comment