Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Calculating percentage of trials completed

Hi,

Every 50 trials participants are shown a feedback item telling them they can take a self-timed break. In the same item, I would like to show them what percentage of trials they have completed. I tried to do this the following way: a JavaScript item before the sequence that contains this in the Prepare tab:

vars.total_trials = 958;
vars.count_trials = (vars.count_trial_sequence) + 1;

Then, before the feedback item I added another JavaScript item with this in the Run tab:

vars.completed = (vars.count_trials / vars.total_trials) * 100;

In the feedback item, I put the text "You have completed [completed] % of trials.

However, when I tested the experiment in the browser, I always got "You have completed NaN % of trials". Is this because the two variables I defined are integers and the "completed" variable is a float? Or do I need to place the JavaScript items in different locations? I could change the feedback item to saying that they have completed X trials out of 958 by using using count_trial_sequence but I'd prefer to use percentages.

Thanks!

Comments

  • Hi @sflu,

    Not sure without seeing the task but if you define vars.count_trials in the "prepare phase", I don't think vars.count_trial_sequence has a value yet. It think it should be in the run tab.

    In any case, just output things to the console in the trial sequence and you'll be able to check the value of your variables as the task goes, and you'll be able to track where the issue is.

    Best,

    Fabrice.

    Buy Me A Coffee

Sign In or Register to comment.