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


#1



can you check my code

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


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


#2

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:


#3

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?


#4

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


#5

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

#6

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