8. Adding an additional if statement re-prompting the user


#1

https://www.codecademy.com/en/courses/ruby-beginner-en-JdNDe/0/8?curriculum_id=5059f8619189a5000201fbcb

I completed the Thith Means War section and was curious about the exercises mentioned in the last section.
How would you re-prompt the user if they do not enter anything...

print 'Please type something' 
    user_input = gets.chomp
    user_input.downcase!
if user_input.include? "s"
    user_input.gsub!(/s/, "th")
else 
    puts "There are no s's in your string" 
end 

puts "You\'ve been duckified #{user_input}! "

#2

You don't know how many times you will have to re-prompt the user so you should use while or until loop. You can use #empty? to test if string is... empty :slight_smile:

print 'Please type something' 
user_input = gets.chomp

while user_input.empty?
    print 'Empty string? Really? Give me some input!'
    user_input = gets.chomp
end

print 'Nice input. Thanks.'

#7