Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Operators and Control Structures Logical Operators Practice time! Operators and Control Structures

Nicolas Hémidy
Nicolas Hémidy
8,481 Points

Issue with case and !

Hi everyone,

I have an issue with my code. I tried to test some ideas with the code presented in the video.

def get_name() print "Enter your name: " return gets.chomp end

def greet(name) puts "Hi #{name}!" if (name == "Nicolas") puts "That's a greet name" end end

def get_number() print "What number would you like to test? " return gets.chomp.to_i end

def divisible_by_3?(number) return (number % 3 == 0) end

name = get_name() greet (name) number = get_number()

case divisible_by_3?(number) when number % 3 == 0 puts "Your number is divisible by 3!" when !(number % 3 == 0) puts "Your number is not divisible by 3!" end

What i want is to return a different string depending on the value of the number. But it always return me "Your number is divisible by 3!".

I really thank you for your help ! Have a good day, Nicolas

Nicolas Hémidy
Nicolas Hémidy
8,481 Points

I found the solution.

def get_name() print "Enter your name: " return gets.chomp end

def greet(name) puts "Hi #{name}!" if (name == "Nicolas") puts "That's a greet name" end end

def get_number() print "What number would you like to test? " return gets.chomp.to_i

end

def divisible_by_3(number) case when number % 3 == 0 puts "Your number is divisible by 3!" when !(number % 3 == 0) puts "Your number is not divisible by 3!" end end

name = get_name() greet (name) number = get_number() divisible_by_3 (number)

I should have gone deeper. Nicolas