There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Can anyone help me figure out why I am getting the error code " Did you create a variable called checking_account?"
class Account
attr_reader :name
attr_reader :balance
def initialize(name,balance=100) @name = name @balance = balance
end
private
def pin @pin = 1234
end
private
def pin_error
return “Access denied: incorrect PIN.”
end
public
def display_balance(pin_number) @pin_number = pin_number
puts “Balance: $#{@balance}.”
else
puts “pin_error”
end
public
def withdraw(pin_number,amount)
puts “withdrew #{amount}. New balance: $#{@balance}.”
else
puts “pin_error”
end
checking_account = Account.new(“Brian”, 7500)
end
Basically, you create a new Account which is fine. Then you try to withdraw some money from this account. In the withdraw method, you have the condition if pin_number == @pin, but the thing is that the instance variable @pin hasn’t been initialized yet. So, the condition evaluates as false.
If you use the condition if pin_number == pin, then the issue can be avoided. See the linked post for more detail. If still confused about something, share your thoughts.