Opening an Account

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/ruby-beginner-en-32cN3/0/6?curriculum_id=5059f8619189a5000201fbcb

<In what way does your code behave incorrectly? Include ALL error messages.>
Instructions
Last step: create an instance of your Account class called checking_account. Give it whatever name and starting balance you like!

I purposely entered a wrong PIN yet it allowed me to withdraw and checked my balance. What’s wrong with my account? haha, I don’t want that to happen to my account ever. Can you help me?

```

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

private
def pin
    @pin = 1234
end

private
def pin_error
    return "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)
    if (pin_number = pin)
        @balance-=amount
        puts "Withdrew #{amount} New balance: $#{@balance}"
else
    puts pin_error
end
end

end

checking_account = Account.new(“Alger”, 8_000_000)
checking_account.withdraw(11, 500_000)
checking_account.display_balance(1285)
checking_account.withdraw(8569, 500_000)
checking_account.display_balance(1234)

<do not remove the three backticks above>

if(pin_number = pin) should be

if(pin_number == pin)

= is setting a value
== is checking if a value is equal to

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