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 Foundations Methods Instance Methods

undefined method `+' ???

Hello,

I followed what Jason said to deposit(1000) but I always get this: 2.2.1 :003 > bank_account.deposit(1000) NoMethodError: undefined method +' for nil:NilClass from /Users/ann/Source/methods/bank_account.rb:9:indeposit' from (irb):3 from /Users/ann/.rvm/rubies/ruby-2.2.1/bin/irb:11:in `<main>'

can you let me know what's wrong?

Thanks.

2 Answers

Hello! Thanks for the quick reply. This is my code here:

class BankAccount def initialize(first_name, last_name) @blance = 0 @first_name = first_name @last_name = last_name end

def deposit(amount)
    @balance += amount 
end 

def withdraw(amount)
    @balance -= amount
end

end

Ethan Lowry
Ethan Lowry
Courses Plus Student 7,323 Points

You have a typo in your code - read over it carefully and other than that it's fine.

Hello Ethan,

I fixed it. hahahah. checked few times but still missed it. My bad.

Thanks. :D

Ethan Lowry
Ethan Lowry
Courses Plus Student 7,323 Points

No problem Johnny. Also try and remember to leave comments rather than new answers on the question in future (what you marked as Best Answer here is actually your own comment, for example).

Thanks

Ethan Lowry
PLUS
Ethan Lowry
Courses Plus Student 7,323 Points

This error is a common one, and it means some object you're trying to call a method (in this case addition or concatenation) on is nil, rather than the string / number / whatever you're expecting it to be.

Check everywhere in your code where you're assigning things to variables and make sure everything is right and not returning nil instead of what you expect.

If this doesn't help, please post your code so we can take a look.