function end_trial() {

			// stop the audio file if it is playing
			// remove end event listeners if they exist
			if(context !== null){
        audio.stop();
				audio.onended = function() { }
			} else {
				audio.pause();
				audio.removeEventListener('ended', end_trial);
			}

      // kill any remaining setTimeout handlers
      jsPsych.pluginAPI.clearAllTimeouts();

      // gather the data to store for the trial
      var trial_data = {
        "rt": response.rt,
        "stimulus": trial.stimulus,
        "button_pressed": response.button
      };

      // clear the display
      display_element.innerHTML = '';

      // move on to the next trial
      jsPsych.finishTrial(trial_data);
    }
// function to end trial when it is time
function to end trial when it is time
function to end trial when it is time
function end_trial() {
			if(context !== null){
        audio.stop();
				audio.onended = function() { }
			} else {
				audio.pause();
				audio.removeEventListener('ended', end_trial);
			}
      jsPsych.pluginAPI.clearAllTimeouts();
      var trial_data = {
        "rt": response.rt,
        "stimulus": trial.stimulus,
        "button_pressed": response.button
      };
      display_element.innerHTML = '';
      jsPsych.finishTrial(trial_data);
    }
function end_trial ( ) { if ( context !== null ) { audio . stop ( ) ; audio . onended = function ( ) { } } else { audio . pause ( ) ; audio . removeEventListener ( 'ended' , end_trial ) ; } jsPsych . pluginAPI . clearAllTimeouts ( ) ; var trial_data = { "rt" : response . rt , "stimulus" : trial . stimulus , "button_pressed" : response . button } ; display_element . innerHTML = '' ; jsPsych . finishTrial ( trial_data ) ; }
function to end trial when it is time
function to end trial when it is time
// stop the audio file if it is playing // remove end event listeners if they exist // kill any remaining setTimeout handlers // gather the data to store for the trial // clear the display // move on to the next trial