Oops, try again. Did you create a variable called checking_account?

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

can you check my code
<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/ruby-beginner-en-32cN3/0/6?curriculum_id=5059f8619189a5000201fbcb

<In what way does your code behave incorrectly? Include ALL error messages.>

```

class Account
attr_reader :name
attr_reader :balance

def initialize (name, balance=100)
    @name = name
    @balance = balance
end
def display_balance (pin_number)
      if pin_number == pin
          puts "Balance: $#{@balance}."

      else
          puts pin_error
      end
end
def withdraw(pin_number, amount)
    if pin_number = pin
      balance=balance - amount
      puts "Withdrew #{amount}.  New balance: $#{@balance}." 
    else 
      puts pin_error
    end
end

checking_account = Account
name = “cruise”
balance = 900
private
def pin
@pin = 1234
end
def pin_error
“Access denied: incorrect PIN.”
end
end

<do not remove the three backticks above>

Please remember that we create objects of a class by typing classname.new() and then inside the parentheses we provide a list of comma-separated arguments.

Here is an example:

ferrari = Car.new("red", "fast")

Also, we create objects of a class outside the class definition.

Can you now fix your 2 problems? :wink:

yes, I did checking_account = Account.new(“Cruise”, 900) but I get the same error that “Did you create a variable called checking_account?” Can you help?

As always, post you full code please. Remember that this statement needs to be outside the class definition of Account.

class Account
    attr_reader :name
    attr_reader :balance
    
    
    def initialize (name, balance=100)
        @name = name
        @balance = balance
    end
    def display_balance (pin_number)
          if pin_number == pin
              puts "Balance: $#{@balance}."
    
          else
              puts pin_error
          end
    end
    def withdraw(pin_number, amount)
        if pin_number = pin
          balance=balance - amount
          puts "Withdrew #{amount}.  New balance: $#{@balance}." 
        else 
          puts pin_error
        end
    end
checking_account = Account.new("cruise", 900)

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

I got it to work. You were right. Outside the class definition worked.

1 Like