Make PIN changeable?


#1



Hello Ruby community!
I am a diving into Ruby studies and I find this language amazing and exciting.
Codecademy made such a great work with its course but I am getting stuck trying to modify the final project (banking on Ruby).

I want to give users a way to change their PIN code but apparently I am doing something wrong.
With this code, I don't get any error but the new_pin doesn't get saved in the @pin variable.

Any help?

Regards, Valerio.


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(amount, pin_number)
      if pin_number == pin
          @balance -= amount
          puts "Withdrew #{amount}. New balance: $#{@balance}."
      else
          puts pin_error
      end
    end
    
    def pin_change(pin1, new_pin)
      if pin1 == pin
        @pin = new_pin
        puts pin
      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("Valerio", 1_000)
checking_account.pin_change(1234, 1111)


#2

try:
def pin_change(pin1, new_pin)
if pin1 == pin
@pin = new_pin.to_i
puts pin


#3

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