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 Objects and Classes Build a Bank Account Class Adding Transactions

Making a method that pushes new transactions: Works in reality but rejected by code challenge...

OK, so the code:

I write here is rejected by the question, but when I append to it to make this code, it actually works locally:

class BankAccount attr_reader :name

def initialize(name) @name = name @transactions = [] end

def add_transaction(description, amount) @transactions.push(description: description, amount: amount) end end

charliesAccount=BankAccount.new("Charlie Horse") charliesAccount.add_transaction('Dumb purchase', 5) charliesAccount.add_transaction('another dumb buy', 5000)

puts(charliesAccount.name) puts(charliesAccount.inspect)

It will spit out, as expected:

C:\Ruby23\bin>ruby tst.rb Charlie Horse

<BankAccount:0x1bbdd68 @name="Charlie Horse", @transactions=[{:description=>"Dumb purchase", :amount=>5}, {:description=>"another dumb buy", :amount=>5000}]>

Is this a glitch in the question or am I actually screwing something up?

bank_account.rb
class BankAccount
  attr_reader :name

  def initialize(name)
    @name = name
    @transaction = []
  end

  def add_transaction(description, amount)
    @transaction.push(description: description, amount: amount)
  end
end

1 Answer

Grace Kelly
Grace Kelly
33,990 Points

Hi David, the code challenge requires for us to append the values to the @transactions array, in your code you have named it @transaction. Simply change the name on both instances of the name and the code challenge should pass :)