Skip to content

Showing Sum of Money Either Gained or Lost #858

Answered by vijaymarupudi
mshastry2022 asked this question in Q&A
Discussion options

You must be logged in to vote

You can have a variable outside the experiment that keeps track of the totals.

var survey = {
  type: "survey-text",
  questions: [{ prompt: "Enter a number:", columns: 3, name: "Number" }],
  data: { task: "guess-number" }
};

var TOTAL = 0;

var feedback = {
  type: "html-keyboard-response",
  stimulus: function() {
    var guess = JSON.parse(
      jsPsych.data
        .get()
        .filter({ task: "guess-number" })
        .last(1)
        .values()[0].responses
    ).Number;
    if (0 <= guess && guess <= 49) {
      TOTAL += 1;
      return "<p>Gain one cent (+ 1¢)</p>";
    } else if (71 <= guess && guess <= 100) {
      TOTAL += 1;
      return "<p>Gain one cent (+ 1¢)</p>";
    } 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jodeleeuw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants