title: Cannot reassign a variable in Javascript
body: <p>Below, I reassign trigger to be false and yet when I run this, the button.onclick function will still run even once the trigger variable is false. Not sure why this is happening. Need the function to stop if trigger becomes false. </p>
  
  <p>First, I assign the variable trigger to be true. </p>
  
  <p>I declare that if x is less than 33 that trigger should become false and thus the button.onclick function should not work. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// sets the variables
  var n = document.getElementById("number");
  var b = document.documentElement.style;
  var count = 0;
  var x = 0;
  var trigger = true;
  if (trigger == true) {
    button.onclick = function() {
      count++;
      n.innerHTML = count;
      x = Math.floor(Math.random() * 100);
      if (x &lt; 33) {
        b.backgroundColor = "red";
        trigger = false;
      } else {
        b.backgroundColor = "black";
      }
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.root {
    background-color: black;
  }
  
  #number {
    color: white;
    font-size: 100px;
    font-family: Helvetica;
    text-align: center;
    margin: auto;
    border-radius: 1%;
    width: 30%;
    margin-top: 15%;
  }
  
  #button {
    display: block;
    background-color: white;
    outline: none;
    font-size: 15px;
    font-weight: bolder;
    text-transform: uppercase;
    padding: 10px 15px 10px 15px;
    border-radius: 5%;
    margin: auto;
    margin-top: 50px;
    font-family: Helvetica;
  }
  
  #rnum {
    display: block;
    text-align: center;
    font-size: 15px;
    color: white;
    margin-top: 50px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"&gt;
  
  &lt;div id="number" type="number"&gt; 0 &lt;/div&gt;
  &lt;div&gt; &lt;button id="button"&gt; Click &lt;/button&gt; &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>