Defining a method with conditional statements


#1

Hi I am trying to figure out why this method isn't working. Can someone help me out?

def number(i)
i = gets.chomp
unless i.is_a? Integer
return "You must type in an integer."
if i > 0
puts "This is a positive integer!"
elsif i < 0
puts "This is a negative integer!"
else
puts "You typed in zero!"
end
end

number(12)


#2

"What excercise are you on?


#3

This is me working a little on my own to test myself on conditional statements. It's not directly off a Codecademy exercise.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.