Displaying the Balance

<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/en/courses/ruby-beginner-en-32cN3/0/4?curriculum_id=5059f8619189a5000201fbcb#

<In what way does your code behave incorrectly? Include ALL error messages.>
the relevant part of this code is the display_balance method, but i ve included the code in its entirety. It is exactly the same as in the original code in part one as far as i see but doesnt work and gives the following error.

    puts pin_number==pin? "Balance: $#{@balance}.": pin_error
                           ^

(ruby):19: syntax error, unexpected ‘:’, expecting keyword_end
puts pin_number==pin? “Balance: $#{@balance}.”: pin_error

```

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)
    puts pin_number==pin? "Balance: $#{@balance}." : pin_error
end

end

<do not remove the three backticks above>

Have you tried with space before ? ?

thanks, that worked. i thought white space didnt’ count in ruby. are there situations when it does count like this one?

One that comes to mind is .nil?.

if movies[title.to_sym].nil?

In other words, if the title does not exist in the hash, then …

Another would be .is_a?

if n.is_a? (Object)

Couple more that come to mind,

.instance_of?
.kind_of?

What you have above is a ternary expression, so the ? is a stand alone operator.

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