Force User to Answer - gets.chomp


#1

How can we force the user to enter a response?

For example. If the user doesn't type anything, the question would keep looping until the user enters text.


#2

Assuming you're storing the string in a variable, you could use a while loop with the code inside of it to check if the variable is empty with .empty, like this:

while(x.empty?)
   // code
end

#3

As a new Ruby learner I'm still not able to wrap my head around this. Would you be able to show us using the example from the lesson?

Thanks in advance!