question yes or no in ruby [closed]

-4

I'm doing a mini game in ruby I want to make that when the person answers yes, he flies to run the game

Ahem:

print "¿Desea volver a jugar si o no: " 
respuesta = gets.chomp

How do I do it so that when I answer yes, the game is repeated?

    
asked by Jensel Stiven Granobles 11.07.2017 в 20:41
source

1 answer

1

You can use any loop (or cycle) to achieve this, for example, using while :

respuesta = "si"

while respuesta == "si" do
  print "¿Desea volver a jugar si o no: " 
  respuesta = gets.chomp
end

This code generates a variable respuesta with initial value "si" to enter the cycle while , once inside the question "¿Desea volver a jugar si o no: " will be printed again and again until the user types the word "no" .

It is important to note that with any other value that the user types (different from "si" ), the game will end (if you want it to be the other way around, that is, the game will continue unless you type "no" , use until respuesta == "no" ).

    
answered by 11.07.2017 в 21:59