PIN Error


I’ve tried several variations of code and have consulted the Q&A. I cannot get it to recognize my PIN. (@pin or pin). I’ve removed everything that didn’t seem relevant.

class Account
  attr_reader :name
  attr_reader :balance
def initialize (name, balance=100)
  @name = name
  @balance = balance
  def pin
    @pin = 1234
  def pin_error
    "Access denied: incorrect PIN."
def display_balance(pin_number)
        puts pin_number == @pin ? "Balance: $#{@balance}.": pin_error
  def withdraw(pin_number, amount)
   if pin_number == pin
     @balance -= amount
     puts "Withdrew #{amount}. New balance: $#{@balance}."
   else puts pin_error
  def deposit(amount)
    @balance += amount
    puts "Ok, your new balance is $#{@balance}. Thanks for stopping by! :-)"

checking_account ="Alex", 1_000)

puts "what would you like to do?"
puts "---Try typing 'deposit' to make a deposit."
puts "---Try typing 'check balanace' to see what ya got!"
puts "---Try typing 'withdraw' to get some out!"

response = gets.chomp

case response
  when "check balance"
  puts "PIN Please: "
  num = gets.chomp

There are several other case responses, but I removed them to cut down on clutter. I keep getting an error that says the PINs don’t match. I’ve also tried using “num.to_i” after the gets.chomp line. Please help, I’m so lost


The string must have at least one uppercase letter or this will become, nil.

Remove the bang (!) and add it to your first line…

response = gets.chomp.downcase

It probably does not matter, but I’ve mostly seen the public code above the private code. Will take some checking to see if it really does matter or not.


I moved the public methods above the private and still doesn’t recognize the PIN. I also moved the .downcase to the line above as you recommended. No luck.

I thought maybe it had something to do with “@pin” being an integer and “pin_number” being a string, but no luck there either.


Please post a link to the exercise you are on. Thanks.


It’s those “above and beyond” exercises at the end -


@pin is defined in the pin method so just write as you did in the withdraw method:

pin_number == pin

which you will still probably have to do so an integer is passed in, not a string.


Wow, yeah that did it! Man, I could have sworn I tried that before, but I guess I hadn’t.

Thank you for your help!


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