title: How do I use a variable out of its scope
body: <p>My problem is that I cannot use a variable out of it's scope. I am trying to make a typing based game. It will not let me use the variable &quot;p2&quot; out of an if statement. This is not the complete game, and I need to know how to use a variable out of an if statement. I am using JSfiddle. The HTML code is just a button to run the function.
  Here is the JavaScript code:</p>
  <pre><code>function input() {
    var p = window.prompt(&quot;You wake up in a strange bed with a massive headache. There are two doors, one to the left, and one to the right. Which one would you like to go through?&quot;)
    if (p == &quot;left&quot;) {
      var a1 = window.alert(&quot;You decided to go left. You walk up to what seems like another human. It was not. It tears you in half. You got the 'That ended fast' ending.&quot;)
      if (p = &quot;right&quot;) {
        var p2 = window.prompt(&quot;You decided to go right. You look around and find a keycard! Two options: keep going straight or go left. Which direction would you like to go?&quot;)
      }
      if (p2 == &quot;straight&quot;) {
  
      }
    }
  }
  </code></pre>