Opening an Account


#1

Here is the link:
https://www.codecademy.com/en/courses/ruby-beginner-en-32cN3/0/6?curriculum_id=5059f8619189a5000201fbcb

here is my code:
class Account
def initialize(name, balance=100)
attr_reader:name
attr_reader:balance
@name = name
@balance = balance
end

private
def pin
@pin = 1234
end

private
def pin_error 
    "Access denied: incorrect PIN."
end

public 
def display_balance(pin_number)
    if pin_number == pin
        puts "Balance: $#{@balance}."
    else 
        puts pin_error
    end
end

public
def withdraw(pin_number, amount)
    @balance -= amount
    if pin_number == pin
        puts "Withdraw #{amount}. New balance: $#{@balance}."
    else
        puts pin_error
    end
end

end

checking_account = Account.new("Rick", 10_000)

Here is the error I am getting:
undefined method `attr_reader' for #
and
Oops, try again. Your code doesn't look quite right. Feel free to peek back at the code in the first exercise if you need help!

I think the code looks good! unless there is something i am not seeing.


#2

I tried moving the above lines and placing it before def initialize method.

and i wrote it like this:
attr_reader:name, :balance

It worked! I am not sure why it did but it did. anyhow care to elaborate on that? please and thank you.

:slight_smile:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.