Why it`s working


#1

Hello. Im confused. Why its working:


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


I thought, it should be like this:


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


#2

In your second code your have syntax problems:

You're using comments inside your code instead of outside of it.

Also, your $ character should be replaced with a ".


#3

im using comments only in this topic, there is no comments in the real code.
And there is no problems with "$" it
s just a part of text and it`s fine.

p.s. error:
(ruby):21: warning: else without rescue is useless
(ruby):15: syntax error, unexpected keyword_do, expecting keyword_then or ';' or '\n'
(ruby):33: syntax error, unexpected keyword_end, expecting $end


#4

You’re right about the $, I misread the code.

However even without your comments your code still has syntax errors.

Try running it in the labs if you’re not convinced

labs repl.it

An if statement doesn’t expect a do keyword afterwards (since you’re already using an if statement to specify a bit of code).