16/18 Private Affair String vs variable?


#1

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

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/learn-ruby/lessons/object-oriented-programming-ii/exercises/private-affairs
<In what way does your code behave incorrectly? Include ALL error messages.>
Why does return “12345” not work but return 12345 for the private password method ? I did not create a password variable nor a parameter in the private password method.

Please advise.

```

Replace this line with your code.

<do not remove the three backticks above>

#2

do the three backticks
paste your code
do three more backticks


#3
class Account
  attr_reader :name
  attr_reader :balance 
  def initialize (name, balance=100)
    @name = name
    @balance = balance
  end
 public
  def display_balance (pin_number)
    @pin_number = pin_number
    if pin_number == pin 
      puts "Balance: $#{@balance}."
    else puts pin_error
    end
  end
 public
  def withdraw (pin_number, amount)
    @pin_number= pin_number
    @amount = amount
    if pin_number == pin
      @balance = @balance - amount
      puts "Withdrew #{amount}. New balance: $#{@balance}."
    else
      puts pin_error
    end
  end
 private
  def pin
    @pin = 1234;end
 private
   def pin_error
     return "Access denied: incorrect PIN.";end
end
checking_account = Account.new(10_000)


#4

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