Trying to built simple chines zodiac finder

I’m a beginner. Trying to create chinese zodiac. User enters the year
and it shows what year it is in chinese zodiac.

class Zodiac
class Config
@@actions=[0,1,2,3,4,5,6,7,8,9,10,11, ‘quit’]
def self.action; @@actions; end
end

attr_accessor

def launch!

introduction
result = nil
until result == :quit
action1 = get_action
action=calc(action1)
result = do_action(action)
end
conclusion
end

def introduction
puts “Welcome!”
end

def conclusion
puts “Bye bye!!!”
end

def get_action
response = nil
puts “In what year were you born?”
print “>”
user = gets.chomp
return response
end

def calc (action)
calculate = (action - 5) % 12
return calculate
end

def do_action(action)
case action
when ‘0’
puts “Your chinese zodiac is ‘RAT’”
when 1
puts “Your chinese zodiac is ‘Ox’”
when 2
puts “Your chinese zodiac is ‘Tiger’”
when 3
puts “Your chinese zodiac is ‘Rabbit’”
when 4
puts “Your chinese zodiac is ‘Dragon’”
when 5
puts “Your chinese zodiac is ‘Snake’”
when 6
puts “Your chinese zodiac is ‘Horse’”
when 7
puts “Your chinese zodiac is ‘Sheep’”
when 8
puts “Your chinese zodiac is ‘Monkey’”
when 9
puts “Your chinese zodiac is ‘Rooster’”
when 10
puts “Your chinese zodiac is ‘Dog’”
when 11
puts “Your chinese zodiac is ‘Pig’”
when ‘quit’
return :quit
end
end

end

zodiac=Zodiac.new
zodiac.launch!


Hi there,

There are lots of things you’ll want to tweak in order to get this
working. (For example, right now it assumes a 1:1 relationship between
Western calendar years and Chinese zodiac signs.)

To fix your specific problem, though, you need to do just a couple of
things:

  1. Change line 38 from

    calculate = (action - 5) % 12

to

calculate = (action.to_i - 5) % 12

^ Right now you’re using gets to take data, which inputs a string. You
cannot subtract from a string, so you must convert to an integer to get
the subtraction to work.

  1. Change line 34 from

    return response

to

return user

^ Response is nil, so without a change like this it’ll return nil, and
nothing happens.

Hope that helps!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs