(off platform) Text story displaying mutliple answers


<Below this line, add a link to the EXACT exercise that you are stuck at.>
This isn’t part of an exercise, I was using repl.it to do this. Here is the link to the project: https://www.repl.it/C1DT/0

<In what way does your code behave incorrectly? Include ALL error messages.>
I am making a short text-based story as a small experiment. I used variables and if/else scripts to make the story. The story line has multiple choice answers with options 1, 2, and 3. For some reason when I enter 3 in the first option, it shows the script after 3 and the script that was supposed to only run if I answered 1, and then answered 3 on the second mutli-choice answer after I answered number 1. Here is the full code.

``` #setting up first path puts "You are walking, what do you do?" puts "1: turn left" puts "2: turn right" puts "3: keep going" answer1 = gets.chomp

if answer1 == “1”
puts “you turn left. You see a monster. What do you do?”
elsif answer1 == “2”
puts “you turn right. You find a sword in a stone. What do you do?”
else answer1 == “3”
print “You keep walking forever and ever. You pass through town after town and become a legend known as ‘The Wanderer’ and walk around the earth for the rest of time.”

#aftertermath of answer 1
if answer1 == “1”
puts “1: you try to fight it”
puts “2: you run”
puts “3: you turn back around”
answer2 = gets.chomp
if answer1 == “2”
puts “1: You try to pick get it out of the stone.”
puts “2: You stare at it and think about how it got there.”
puts “3: You ignore it and keep going.”
answer3 = gets.chomp

#aftermath of turning left
if answer2 == “1”
puts “You died.”
elsif answer2 == “2”
puts “You run away succesfully”
else answer2 == “3”
puts “You turn back around”
#aftermath of turning right
if answer3 == “1”
puts “You try to pick up the sword but instead fall backwards onto a sharp rock and bleed to death.”
elsif answer3 == “2”
puts “You continue to look at it. As you watch it, it seems to glow slightly. You contemplate this glow, wondering if it has any meaning. As time passes, you stare more and more at this currios object. ‘Where did it come from? Where did it go? Did it belong to cotton eyed Joe?’ More and more time passes, and before you realize it, it’s been 7.1 billion years and the sun has expanded so much that it swallows up the entire earth. You died.”
else answer3 == “3”
puts “you walk into a hole and die.”

<do not remove the three backticks above>

Look for things like the above. Clearly, an else cannot have a condition. Maybe an elsif?


Look for ways to refactor that include case..when structures, and limit if..else structures to confined scopes. This will help you organize your code.

Also look for ways to separate (or at least confine) textual content from code. heredoc is a handy tool for that. (Link chosen from SERP)