Python to JS Code Error

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Mac Big Sur):
PsychoPy version (2021.1.2):

**What are you trying to achieve?: I’m running an RT study and trying to provide a “Too Slow” feedback message if RT > 1.5s, but to provide the actual RT when the participant is correct and less than 1.5s. The code runs fine on my local machine but gets hung up “initialising” in Pavlovia.

I’m a novice at Python and JS coding, but here’s the JS code that I inserted manually:

if (resp.rt > 1.5) {
msg = “Too Slow”;
} else {
if (resp.corr) {
msg = “Correct! RT=” + resp.rt.toFixed(3);
} else {
msg = “Incorrect”;

Try it without .toFixed(3) to see if that’s the issue.

Also, take a look at the Browser console for the specific error and use Auto translate code when possible.

Yes, I thought that might be something that wouldn’t translate.

Thanks for the input. The program now works, but the toFixed(3) bit actually was not the problem. The auto Python - JS code option also gave me the “Python code error” and wouldn’t translate. However, I discovered that a quotation mark had the wrong orientation in my second line. I copied and pasted from MS Word on my Mac and I think there are different defaults for how to present a quotation mark… Its often the stupid mistakes…

That is exactly why I recommend using Auto translate code components even when writing Python code for offline use only.

I’m afraid that when using the Auto translate option it says there’s a problem with the Python code and nothing translates over to JS. The Python code works fine, though, because the program runs locally on PsychoPy.