0
I have a Ruby exercise where I have functions to make a simple guessing game with a whole number.
After implementing the function 'pede_um_numero' passing the parameters, you are giving error when compiling on lines 30, 31 and 17 where points the variable 'attempt' as not defined locally or method. (maior_ou_menor.Rb:17:in pede_um_numero': undefined local variable or method
attempt' for main:Object (Nameerror))
I took a look at the code looking for typos but without success, I tried to fix the code indentation, also without success. It’s my first time messing with Ruby, follow the code snippet.
EDIT with the entire code for better understanding.
def da_boas_vindas
puts "Bem vindo ao jogo da adivinhação"
puts "Qual é seu nome?"
nome = gets
puts "\n\n Começaremos o jogo para você " + nome
end
def sorteia_numero_secreto
puts "\nEscolhendo um número entre 0 e 200..."
sorteado = 175
puts "Escolhido... que tal adivinhar hoje nosso número secreto?\n\n"
sorteado #return sorteado
end
def pede_um_numero(tentativa, limite_de_tentativas)
puts "Tentativa " + tentativa.to_s + " de " + limite_de_tentativas.to_s
puts "Entre com um número"
chute = gets
puts "Será que acertou? Você chutou " + chute
chute
end
da_boas_vindas
numero_secreto = sorteia_numero_secreto
limite_de_tentativas = 5
for tentativa in 1..limite_de_tentativas
chute = pede_um_numero(tentativa, limite_de_tentativas)
acertou = numero_secreto == chute.to_i
if acertou
puts "Acertou!"
break
else
maior = numero_secreto > chute.to_i
if maior
puts "O número secreto é maior!"
else
puts "O número secreto é menor!"
end
end
end