Feedback msg not working correctly online

My feedback message works fine when I run the experiment on my computer, but when I run it on Pavlovia, the feedback message is always “wrong.” I think it’s probably because I translated the python code incorrectly to js code. How would you translate the python code below to JS code? Thanks!

Here’s my python code for feedback:

if not key_resp.rt:
    msg = 'Failed to respond'
elif key_resp.keys[-1]==corrAns:
    msg = 'Correct!'
else:
    msg = 'Wrong!'

Hi @CatK, your JS code is ok (from previous post), but its how you have set your correct answer variable - you need to set corrAns as a string rather than Number. This is because the JS code uses strict equality checks that do not ignore type, so a string and number can never be equal, even when comparing 1 vs “1”. So, if corrAns === 1 and resp_key.keys === 1, they will not be equal and you will not log a correct answer for your keyboard.

If you want to know more, look up strict vs loose (=== vs ==) equality checks in JavaScript.

Thank you! But after I changed the value of corrAns to string, it still doesn’t work. What else could be wrong? Or am I not changing the code correctly? Thankstesting to del.psyexp|attachment (21.4 KB)

Thank you! But after I changed the value of corrAns to string, it still doesn’t work. What else could be wrong with my code? Or am I not changing the code correctly? Thanks!

testing to del.psyexp (21.4 KB)

Ok, well if you have not already done so, you will need to change the values to string in the if statement as well, in the codeLearn routine.

I did it but it still doesn’t work.

Ok great, well that version you posted works for me, so I think perhaps you need to refresh your browser cache using CTRL + F5 (if using Windows) to get the most up to date version.

E.g., here is running version you just uploaded

https://run.pavlovia.org/dvbridges/testing_catk2/html/

By the way, the conditional statement in the codeLearn routine seems to always set corrAns to 1:

if (item <= 12){
    corrAns = '1';}
else{
    corrAns = '1';}

I created a new project for the same experiment. Now it works. Thanks a lot!