Feedback to text input not correct in Pavlovia

Hi everyone,

OS : Win10

PsychoPy version : 2020.2.3

Standard Standalone? : Yes. Using the Builder (I also manually changed some of the JavaScript code)

What are you trying to achieve?: In my experiment, I first collect text input from participants (e.g., “cui1”), then I provide feedback regarding whether the input is correct.

Problem: The feedback part breaks after I put this experiment online. The feedback part always judges the text input to be wrong (i.e., even correct answers are judged to be wrong).

What did you try to make it work?: (1) Forcing the text input and the correct answer into string by using the String() function; (2) Changing the position of the if statements for feedback.

Link to the script: https://gitlab.pavlovia.org/yzengaeKU/pwi_session_1/blob/master/Session_1_building.js

Code of the if statements:

// check corect answers
if (String(text.text) == String(correct)) {
    display = "conditions/Slide9.JPG";
    opacity = 0;
    color = "white";
} else {
    display = "conditions/Slide10.JPG";
    opacity = 1;
    color = "red";
}

Many thanks for your help!!!

Hi Yuyu,

It looks like you set text.text to blank right before this if else statement (line 511).

Also, I couldn’t find where the variable correct was defined in the script.

Best,
Joyce

Also, when in doubt, insert some temporary debugging code to check that the values are what you expect, e.g.

console.log(text.text)
console.log(correct)

Hi Joyce,

Thank you very much for your reply!

The variable correct refers to a column in the condition file (line 221), which pairs the displayed target word and the correct answer for each trial.

Thank you very much!

Best,

Hi Michael,

Thank you so much for introducing console.log() to me. This is super useful!

I added console.log(text.text) and console.log(correct) before the if statement (now line 503 and 504). Unfortunately, console.log() seems to show that even when text.text and correct are equal, the if statement still judges it to be false …

er2 [Feedback.js:503:13]

er2 [Feedback.js:504:13]

Best,

I got the issue solved by doing two things: (1) displaying the correct (setting the opacity to 0 so the appearance of the experiment stays the same); (2) using .valueOf() expression for comparison of texts. Below are the relevant codes.

Text_typing_correct.setText(corrAns)

if ((String(text.text).valueOf() === String(corrAns).valueOf())) {
        feedback_pic = 'pages/b_typing/Session_1_typing_correct.JPG';
        feedback_opac = 0;
        feedback_color = "white";
    } else {
        feedback_pic = 'pages/b_typing/Session_1_typing_wrong.JPG';
        feedback_opac = 1;
        feedback_color = "red";
    }

Many thanks for everyone’s input!!