Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Jacob Hyten
Jacob Hyten
1,849 Points

Getting an error when entering Number

My code runs fine until after I enter a number. Once I enter the number. I get this error:

number.rb:18:in 'divisible_by_3': wrong number of arguments (1 for 0) (ArgumentError) from number.rb:26:in '<main>'

Here is my code. I can't seem to figure out what is wrong with it.

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

def greet(name)
  puts "Hi #{name}!"
  if name == "Jacob"
    puts "That is a great name"
  end
end

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

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

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

if divisible_by_3(number)
  puts "Your number is divisible by 3"
end

2 Answers

Iain Diamond
Iain Diamond
29,379 Points
...
def divisible_by_3() 
  return (number % 3 == 0) 
end

...
number = get_number()

if divisible_by_3(number) 
  puts "Your number is divisible by 3" 
end

Hi Jacob,

You've defined divisible_by_3() with no arguments, but you're calling it with a number.

Hope this helps, iain

The answer is in the error - wrong number of arguments (1 for 0), review your divisible by 3 method definition.