title: calling a function within a function not working, uncaught TypeError
body: <p>This might sound similar to other questions, but just hear me out. I have a function called <code>bullet(x, y, w, h)</code> and a function inside that called <code>this.trigger()</code> i want to call the <code>this.trigger()</code> in a keyDown function.</p>
  
  <p>This is the bullet function
  <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> function bullet(x, y, w, h) {
  
    //x value of bullet is the x value of the player + 27
    this.x = player.x + 27;
  
    //y value of bullet is the y value of the player
    this.y = player.y;
  
    //the width of the bullet
    this.w = w;
  
    //the height of the bullet
    this.h = h;
  
    //boolean for whether fired is true or false
    this.fired = false;
  
    //This function draws the player
    this.draw = function() {
  
     // states what x of the bullet is
     this.x = player.x + 28;
  
     //sets fillStyle to "red"
     context.fillStyle = "red";
  
     //Fills the rectangle red
     context.fillRect(this.x,this.y,5,10);
  
    };
  
  
    //function which moves the bullet
    this.trigger = function() {
  
     //If this.fired = true; if statement runs
     if(this.fired) {
      //makes the bullet's y value go down by 10
      this.y -= 10;
     }
  
     //If the bullet's y value is lower than 0; if statement runs
     if (this.y &lt; 0) {
  
      //this.fired is now false
      this.fired = false;
  
      //sets the bullet y value to player y value
      this.y = player.y;
  
     }
  
    };
  
   }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is the keydown function:</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> // controls to shoot the bullet when the user presses the key
   document.addEventListener("keydown", function(e) {
  
    //if the player presses the spacebar run the statement
    if(event.keyCode == 32) {
  
     //bullet.fired is now equal to true
     bullet.fired = true;
  
     //calls bullet.trigger
     bullet.trigger();
  
  
   }
  
   });</code></pre>
  </div>
  </div>
  </p>
  
  <p>In this code it comes up with the error: Uncaught TypeError: bullet.trigger is not a function
      at HTMLDocument.</p>
  
  <p>This is also my first time asking a question on stackoverflow so any feedback is appreciated. :)</p>