Mikk Poles Mikk Poles - 3 months ago 16
Ruby Question

syntax error, unexpected keyword_else, expecting ':' - RUBY

prompt("Welcome to Calculator! Enter your name:")

name = ''
loop do
name = Kernel.gets().chomp()

if name.empty()?
prompt("Make sure to use a valid name")
else
break
end
end


Not sure what I'm missing here.

I got this error messsage:

syntax error, unexpected keyword_else, expecting ':'

Answer

Line

if name.empty()? 

is interpreted as ternary 'if' operator inside regular if statement:

if (name.empty() ? do_somethig : do_something_else )

and double dot is missing is not found in your code

maybe you meant this:

if name.empty? # is equal to
if name.empty?()

Because question mark is a part of method name

Comments