5. Making a Withdrawal


#1

Hello
what is wrong with the code:

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

thank you


#2

Plesae edit your post to format the code sample. Enter a new line above the code and insert three backticks, then enter a new line at the end of the code and insert three more backticks.

```

Your code here

```


#3

The above can be written on one line (see lesson one example):

    attr_reader :name, :balance

#4

Spelling error: pin_numer => pin_number


#5

does not help

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

(ruby):31: syntax error, unexpected $end, expecting keyword_end


#6

Should these both read,

    if pin_number == @pin

?


#7

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

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