我似乎无法弄清楚如何阻止if / else语句进入下一个"答案"如果第一个答案不正确。
classic_house_tracks = ['Come on Now Baby', 'Follow Me', 'The Spirit']
puts "Who produced " + classic_house_tracks[1] + "?"
producer_input = gets.chomp.to_s
if producer_input == "Aly-Us" || producer_input == "aly-us" || producer_input == "Aly-us"
puts "Yep, and are Aly-Us from Detroit or Chicago?"
else
puts "Nope, wrong producer."
# break
# end
# that obviously didn't work.
end
(请随时帮助我干掉我的代码,因为我是新手。):)谢谢 任何人都可以帮忙!
答案 0 :(得分:0)
使用return
关键字,如果返回string
,则会退出代码。
你也可以把它干得如下:
classic_house_tracks = [
'Come on Now Baby',
'Follow Me',
'The Spirit'
]
puts "Who produced #{classic_house_tracks[1]}?"
producer_input = gets.chomp.to_s
if producer_input.downcase == "aly-us"
puts "Yep, and are Aly-Us from Detroit or Chicago?"
else
return "Nope, wrong producer."
end