8.0 Congratulationth!


#1

Hi All,

Just encountered an issue with the output that the interpreter spills out! So basically I am creating a while statement so that if the user does not input their name it will notify the user. However my problem is how do I make the program ignores the previous 'if' statement and just works with 'while' if no input has been entered. My code is below followed by the output.

print "Enter character name"
user_input = gets.chomp.downcase

if user_input.include? "s"
user_input.gsub!(/s/, "th")
puts "Your name is #{user_input}!"

else puts "Your name is #{user_input}!"

end

while user_input.empty?
puts "You have not entered a name, please retry"
user_input = gets.chomp

end

Below is the outcome if I just hit enter with no name entered.

Enter character name
Your name is !
You have not entered a name, please retry

Any help would be great I'm trying to get this program fully functional on the last exercise:)

Many thanks,

HydroHat!


#2

It runs from top to bottom, so if you want one thing to happen before another, you'll have to put that one thing above the other in the code file.


#3

Ionatan you god! Thank you so much for that, I had a feeling this was the case after posting this but didn't have time to test it!

Also now that I know it runs from top to bottom has really helped me I wasn't sure if certain functions were given priority.

Live long and prosper!