6 Opening a New Account


#1

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

I can't seem to decipher what is wrong here. Have crosschecked with exercise 1 and still can't make it out.
Getting:
(ruby):22: warning: else without rescue is useless
undefined method `attr_reader' for #<Context::Account:0x00000000b07f48 @name="Joe", @balance=1000>

Any help would be massively appreciated.

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

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

public
def display_balance(pin_number)
    puts "Balance: $#{@balance}." if pin_number == pin
    else 
        puts 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
  end
  
  checking_account = Account.new("Joe", 1000)

#2

you know it has to do with your if else statement usually not having closing end keyword check you display_balance method


#3

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