I’m getting the error - ‘Oops, try again. Did you add a public withdraw method to your Account class?’, but I’m struggling to see where I’ve gone wrong?
class Account
attr :name
attr :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)
if pin_number == @pin
puts "Balance: $#{@balance}."
else
puts = pin_error
end
def withdraw (pin_number, amount)
if pin_number == @pin
@balance -= amount
puts "Withdraw #{amount}. New balance: $#{@balance}."
else
puts = pin_error
end
end
EXACT SAME ISSUE. MIT KEEPS ASKING IF I CREATED A PUBLIC METHOD FOR MY ACCOUNT CLASS BUT YOU DON’T EVEN NEED TO WRITE PUBLIC FOR IT TO WORK. NOT SURE. (SORRY FOR CAPS, HELPS TO SEE CODE VS WRITING.
class Account
attr_reader :name, :balance
def initialize(name, balance=100) @name = name @balance = balance
end
def display_balance(pin_number) @pin_number = pin if puts “Balance: $#{@balance}.”
unless @pin_number != pin then 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
private
def pin(pin) @pin == pin
pin = 1234
end
def pin_error
puts “Access denied: incorrect PIN.”
end
end
end
I had the exact same problem, I only forgot to add “puts” after the else statement.
Only two things I can find different between yours and mine.
1st: “if pin_number == pin” part. It should be comparing itself to @pin.
2nd thing is the else part in the same method, where you are calling an argument. And you should be able to call the method you made earlier by just stating its name.
And the post from a month ago, that user should also look at his else statement.