Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Operators and Control Structures Ruby Control Structures The Ruby Elsif Statement

my program won't run

print "Enter name: " name = gets.chomp

if name == "Nick" puts "That's my name, too!" else puts "Hi #{name}!" end

print "Modify your name. Type 'uppercase' or 'reverse': " answer = gets.chomp.downcase

if answer == "reverse" puts "This is your name backwards:" puts name.reverse else if answer == "uppercase" puts "This is your name in all uppercase letters:" puts name.upcase else if answer == "both" puts name.reverse.upcase else puts "Okay, Maybe Later." end

I keep getting this error every time I try to run and compile it.

control_structures.rb:23: syntax error, unexpected end-of-input, expecting keyword_end

2 Answers

Marco van Vemden
Marco van Vemden
12,553 Points

Hi Nick, In Ruby, the syntax for "else if" is "elsif".

print "Enter name: " 
name = gets.chomp

if name == "Nick" 
  puts "That's my name, too!" 
else 
  puts "Hi #{name}!" 
end

print "Modify your name. Type 'uppercase' or 'reverse': " 
answer = gets.chomp.downcase

if answer == "reverse" 
  puts "This is your name backwards:" 
  puts name.reverse 
elsif answer == "uppercase" 
  puts "This is your name in all uppercase letters:" 
  puts name.upcase 
elsif answer == "both" 
  puts name.reverse.upcase 
else 
  puts "Okay, Maybe Later." 
end

I tried that and it never runs properly.

Marco van Vemden
Marco van Vemden
12,553 Points

What do you mean by "it never runs properly"? Copy and past the code in your Ruby workspace, and run it. Just tested it again myself and all is working fine.