one for the "if" statement, and one for the "unless" statement within that if statement.
print "are you hungry?"
answer = gets.chomp
if answer === "yes"
hungry = true
unless answer === ("no" || "yes")
puts "yes or no"
hungry = false
as far as i can tell, this part of the code works perfectly,.
if i check at the end, answering "yes" makes hungry == true, and "no" makes hungry == false, while giving neither of those answers brings the "yes or no" message.
the issue is with the lower part of the code.
if answer === ("no" || "yes")
unless hungry === true
puts "I'm writing Ruby programs!"
puts "Time to eat!"
else puts "use your head"
so, if the answer was either "no" or "yes" the if statement should run, which should start the "unless" statement just like in the previous code. so if hungry does not == true, it should put "i'm writing ruby programs!" which it successfully does.
if hungry != true, the unless statement SHOULD run the else statement which puts "time to eat!" and then there is an "end" to close the unless statement.
then, back to the original "if" statement, if answer is neither "no" or yes", it should put "use your head", which it will successfully do.
some reason though, instead of running the else statement within the unless statement, having hungry == true skips that line entirely, and goes to the last else which is outside of the "unless" statement, and shouldn't be running unless answer === ("no" || "yes")
so i have no idea why it skips, and the unless statement doesn't seem to be contained.
removing any of the "end"s will cause the code to fail, which should mean they close the "unless" statements as i expect them to.