Mikk Poles Mikk Poles - 1 year ago 84
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")

Not sure what I'm missing here.

I got this error messsage:

syntax error, unexpected keyword_else, expecting ':'

Answer Source


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download