Always "Access denied: incorrect PIN."


#1

https://www.codecademy.com/courses/learn-ruby/lessons/banking-on-ruby/exercises/opening-an-account?action=lesson_resume&link_content_target=interstitial_lesson

Why am I getting Access denied always?

I’m not able to perform no one action even display the balance



class Account
  attr_reader :name
  attr_reader :balance
  def initialize(name, balance=100)
    @name = name
    @balance = balance
  end
  
  public
  def display_balance(pin_number)
    if pin_number == @pin
      puts "Balance: $#{@balance}."
    else
      puts pin_error
    end
  end
  
  def withdraw(pin_number,amount)
    if pin_number == @pin
      @balance -= amount
      puts "Withdrew #{amount}."
    else
      puts pin_error
    end
  end
  
  def deposit(pin_number, amount)
    if pin_number = @pin
      @balance =+ amount
      puts "Deposit of #{amount}."
    else
      puts pin_error
    end
  end

  private
  def pin
    @pin = 1234
  end
  def pin_error
    return "Access denied: incorrect PIN."
  end 
end

checking_account = Account.new("Flamarion", 1000)
checking_account.display_balance(1234)


#2

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