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

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.