function end_trial() {

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

      // Infer choice
      if (trial.left && response.button==0) {
        response.choice = 1;
      } else if (trial.left && response.button==1) {
        response.choice = 0;
      } else if (response.button==0) {
        response.choice = 0;
      } else {
        response.choice = 1;
      }

      // Sample outcome
      if (response.choice == 1) {
        trial.outcome = jsPsych.randomization.sampleWithReplacement([trial.A1, trial.A2], 1, [trial.pA1, trial.pA2])[0];
      } else {
        trial.outcome = jsPsych.randomization.sampleWithReplacement([trial.B1, trial.B2], 1, [trial.pB1, trial.pB2])[0];
      }

      // gather the data to store for the trial
      var trial_data = {
        "pA1": trial.pA1,
        "A1": trial.A1,
        "pA2": trial.pA2,
        "A2": trial.A2,
        "pB1": trial.pB1,
        "B1": trial.B1,
        "pB2": trial.pB2,
        "B2": trial.B2,
        "left": trial.left,
        "button": response.button,
        "choice": response.choice,
        "rt": response.rt,
        "outcome": trial.outcome
      };

      // 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() {
      jsPsych.pluginAPI.clearAllTimeouts();
      if (trial.left && response.button==0) {
        response.choice = 1;
      } else if (trial.left && response.button==1) {
        response.choice = 0;
      } else if (response.button==0) {
        response.choice = 0;
      } else {
        response.choice = 1;
      }
      if (response.choice == 1) {
        trial.outcome = jsPsych.randomization.sampleWithReplacement([trial.A1, trial.A2], 1, [trial.pA1, trial.pA2])[0];
      } else {
        trial.outcome = jsPsych.randomization.sampleWithReplacement([trial.B1, trial.B2], 1, [trial.pB1, trial.pB2])[0];
      }
      var trial_data = {
        "pA1": trial.pA1,
        "A1": trial.A1,
        "pA2": trial.pA2,
        "A2": trial.A2,
        "pB1": trial.pB1,
        "B1": trial.B1,
        "pB2": trial.pB2,
        "B2": trial.B2,
        "left": trial.left,
        "button": response.button,
        "choice": response.choice,
        "rt": response.rt,
        "outcome": trial.outcome
      };
      display_element.innerHTML = '';
      jsPsych.finishTrial(trial_data);
    }
function end_trial ( ) { jsPsych . pluginAPI . clearAllTimeouts ( ) ; if ( trial . left && response . button == 0 ) { response . choice = 1 ; } else if ( trial . left && response . button == 1 ) { response . choice = 0 ; } else if ( response . button == 0 ) { response . choice = 0 ; } else { response . choice = 1 ; } if ( response . choice == 1 ) { trial . outcome = jsPsych . randomization . sampleWithReplacement ( [ trial . A1 , trial . A2 ] , 1 , [ trial . pA1 , trial . pA2 ] ) [ 0 ] ; } else { trial . outcome = jsPsych . randomization . sampleWithReplacement ( [ trial . B1 , trial . B2 ] , 1 , [ trial . pB1 , trial . pB2 ] ) [ 0 ] ; } var trial_data = { "pA1" : trial . pA1 , "A1" : trial . A1 , "pA2" : trial . pA2 , "A2" : trial . A2 , "pB1" : trial . pB1 , "B1" : trial . B1 , "pB2" : trial . pB2 , "B2" : trial . B2 , "left" : trial . left , "button" : response . button , "choice" : response . choice , "rt" : response . rt , "outcome" : trial . outcome } ; display_element . innerHTML = '' ; jsPsych . finishTrial ( trial_data ) ; }
function to end trial when it is time
function to end trial when it is time
// kill any remaining setTimeout handlers
 // Infer choice
 // Sample outcome
 // gather the data to store for the trial
 // clear the display
 // move on to the next trial
