6/7 Opening an account


#1

Hi I am once again having problems with my code can someone help me?

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

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

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

private
def pin
    @pin = 1234
end

def pin_error
"Access denied: incorrect PIN."

end
end
checking_account = Account("Me", 1_000_000)

Error message:
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!

Output:
undefined method `Account' for #


#2

You'll have to explain how you're trying to get it to act differently if we're gonna talk about anything meaningful.


#3

Hi there! I'm new to this, but look at your last two lines:

Output:
undefined method 'Account' for #

Something is missing in this line:

checking_account = Account("Me", 1_000_000)

Do you see it?

Hint: Account.new

And just incase it helps someone, make sure there's no space between the end of Account.new and the brackets, mine wouldn't go through and that was the reason.

Hope this helps :slight_smile:


#4

Yeeees…It helped me a lot actually!
thanks for that!!!