Banking on Ruby ... getting ELSE without rescue is useless


#1



https://www.codecademy.com/courses/ruby-beginner-en-32cN3/0/7?curriculum_id=5059f8619189a5000201fbcb


I got pass on this but why I'm getting that error line in console ? ELSE without rescue ??? What it means ?


class Account
    
    attr_reader :name, :balance
    def initialize(name, balance = 100)
        @name = name
        @balance = balance
    end
    
    
    private
    
    def pin
        @pin = 1234
    end
    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
    
    def withdraw(pin_number, amount)
        if pin_number === pin
            balance -= amount
            puts "New balance: $#{@balance}."
        else if amount > balance
            puts "You don't have enough money."
            
        else
            puts pin_error
        end
    end
    
    def deposit(amount)
        if amount not is_a
            puts "Rubbish !"
        else
            balance += amount
            puts "New balance: $#{@balance}."
    
    
end
saving_account < Account
checking_account = Account.new("mark", 1000)


#2

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