5. Making a Withdrawl


#1



What am I overlooking here? I even compared my code to the code in exercise one, and my withdraw method is written exactly like theirs.

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


Oops, try again. Your code doesn't look quite right. Feel free to peek back at the code in the first exercise if you need help!


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
    return "Access denied: incorrect PIN."
  end
  
  public
  def display_balance(pin_number)
    puts pin_number == pin ? "Balance: $#{@balance}." : pin_error
    end
  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


#2

I reorganized my code so that the public methods were above the private methods. I also removed public (like in the first exercise). This resolved my problem. I'm guessing my code is fine, but doesn't match exactly what they expected to see. Am I wrong on that assumption?


#3

In many instances it is the code pattern being examined, so you could be correct in this assumption. Can't say for sure, though.