# JS Syntax Error! invalid syntax (\<unknown\>, line 1)

**URL:** <https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568>\
**Category:** Online experiments\
**Created:** [October 21, 2024, 6:14pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568 "2024-10-21T18:14:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsdanielaibarra](https://avatars.discourse-cdn.com/v4/letter/i/d07c76/32.png) [@itsdanielaibarra](https://discourse.psychopy.org/u/itsdanielaibarra)\
**Post date:** [October 21, 2024, 6:14pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/1 "2024-10-21T18:14:37Z")

</div>

Hello! I am attempting to transfer my experiment from PsychoPy (v2024.2.3) to Pavlovia.  
When I attempt to select “Write experiment as a Java Script (JS) script” I get the following syntax errors:  
Generating PsychoJS script…

1378.8456 EXP Imported /Users/danielaibarra/Desktop/Decoy/Baseline\_PreTest.xlsx as conditions, 20 conditions, 13 params  
1378.9047 ERROR invalid syntax (, line 1)  
1378.9048 ERROR invalid syntax (, line 1)  
1378.9533 ERROR invalid syntax (, line 1)  
1378.9534 ERROR invalid syntax (, line 1)  
1378.9652 ERROR invalid syntax (, line 1)  
1378.9653 ERROR invalid syntax (, line 1)  
1379.8954 EXP Imported /Users/danielaibarra/Desktop/Decoy/Baseline\_PreTest.xlsx as conditions, 20 conditions, 13 params  
1379.9606 ERROR invalid syntax (, line 1)  
1379.9607 ERROR invalid syntax (, line 1)  
1380.0167 ERROR invalid syntax (, line 1)  
1380.0168 ERROR invalid syntax (, line 1)  
1380.0322 ERROR invalid syntax (, line 1)  
1380.0323 ERROR invalid syntax (, line 1)  
1381.8315 INFO Investigating repo at /Users/danielaibarra/Desktop/Decoy

However, when I attempt to run the current script on Python it works perfectly. I assume the error is due to my custom code? I don’t see how to change this since PsychoPy automatically translates the custom Python code into JS code.

My custom code was:  
if MelodicTone.status == FINISHED:  
continueRoutine = False  
elif BuzzTone.status == FINISHED:  
continueRoutine = False  
elif text\_blankonesec.status == FINISHED:  
continueRoutine = False

and PsychoPy translated it to:  
if ((MelodicTone.status === PsychoJS.Status.FINISHED)) {  
continueRoutine = false;  
} else {  
if ((BuzzTone.status === PsychoJS.Status.FINISHED)) {  
continueRoutine = false;  
} else {  
if ((text\_blankonesec.status === PsychoJS.Status.FINISHED)) {  
continueRoutine = false;  
}  
}  
}

If anyone has any indication as to why I am experiencing syntax errors and am unable to sync my experiment to Pavlovia please let me know!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 21, 2024, 8:04pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/2 "2024-10-21T20:04:45Z")

</div>

There might be something earlier in your experiment, such as in the expInfo dialogue box.

---

<div class="post-metadata">

**Author:** ![itsdanielaibarra](https://avatars.discourse-cdn.com/v4/letter/i/d07c76/32.png) [@itsdanielaibarra](https://discourse.psychopy.org/u/itsdanielaibarra)\
**Post date:** [October 22, 2024, 5:17pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/3 "2024-10-22T17:17:50Z")

</div>

how?

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [October 23, 2024, 9:23am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/4 "2024-10-23T09:23:10Z")

</div>

Hello

You need to provide more information. We just have the information you provide us with. You suspect that the error is in your custom code but that does not have to be the case.

You could, for instance, post a locally running toy-version of your experiment, that you can’t sync, in the forum.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 2, 2024, 9:12am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/5 "2024-11-02T09:12:18Z")

</div>

Hello, I am getting the same error:

ERROR invalid syntax (, line 1)

I wanted to create the same project that is working and syncing fine- but with a slight change, I added a mask in this new project after showing stimuli. So everything is the same. So it starts with screen scale blind spot and so on. At first i realized i accidentally left duration to credit card image to 1s so i changed it, cleared cache, saved exp again and synced again but I-was-seeing credit card image and it disappeared. Then now I added a consent code and loop before the screen scale so at first consent should be shown. But again although i cleared cache and tried with different browser, I am seeing credit card imag and it disappears. And that error I got. What might be the issue here? I am adding the first 10 lines of the code is that it?Thanks a lor for your guidance!

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

- Newversionwmask \*  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

import { core, data, sound, util, visual, hardware } from ‘./lib/psychojs-2024.2.4.js’;  
const { PsychoJS } = core;  
const { TrialHandler, MultiStairHandler } = data;  
const { Scheduler } = util;  
//some handy aliases as in the psychopy scripts;  
const { abs, sin, cos, PI: pi, sqrt } = Math;

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [November 2, 2024, 10:37am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/6 "2024-11-02T10:37:38Z")

</div>

Hello

I do not speak PsychoJS, sorry. I rely on auto-translate from PsychoPy to PsychoJS. Do you have the Python-code?

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 2, 2024, 10:41am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/7 "2024-11-02T10:41:32Z")

</div>

**Hi**

Thanks for the quick response! I actually directly copy pasted this from the coder i thiught the error was referring to this but… after i wrote this entry as i read similar entries,I checked if i missed anything when copy pasting (transferring) experiments and turns out I missed adding some parts of the code and incorrectly referred to the stimuli i should be refereing to in mouse component, (clickable stimuli)now I double checked and added. But 1-consent routine wont work. Its supposed to end the experiment if n is pressed, even i press n i see the screen scale part and credit card image disappears again.

What could be the issue?

Thanks a lot for the guidance!  
Best regards,

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [November 2, 2024, 10:47am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/8 "2024-11-02T10:47:09Z")

</div>

Hello

Your answer is rather confusing. The coder is used to write PsychoPy-experiment in Python, not PsychoJS-programs. Did you mean the builder? Did you use code-components which were auto-translated?

If you have a new problem, better start a new thread with a new heading. Given that you do not provide the routine and component you use for for ending the experiment nobody will be able to tell what does not work.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 2, 2024, 11:01am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/9 "2024-11-02T11:01:31Z")

</div>

**hello**

Yes in my experiment i used code components some of them were auto-js some of them were both some of them were js but these were fine before, i had no problem syncing from the original experiment project, plus screen scale and blind spot is not something i wrote so js- both should not be causing issue i think.

I tried to create a second project, for that I was going to just add masks after stimuli, so i directly copy pasted routines to a new folder. I got that error, then i thought i should be looking at the coder cause i didnt know what first line (ERROR invalid syntax (, line 1))means so what I sent is from the coder.js

As I said when I realized I missed adding some code from my working experiment to this one, I changed them, now I am able to see the consent but still the next routine which is scaling, credit card image disappears again, regardless of consent I think.

and I get the same error but no problem with syncing.

Here are some screenshots:

 ![Screen Shot 2024-11-02 at 13.54.08](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/1/d1d8b5f22f2c7546e46c3c24ce824d77d050b7e5.png)  
 ![Screen Shot 2024-11-02 at 13.54.15](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/9/1960db22be8bc3f4f0b12833e01318e71b9f435d.png)  
 ![Screen Shot 2024-11-02 at 13.54.18](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/3/23a8dfbfb4d3be2cd1a8e2d6d4dc79df33abecc8.png)  
 ![Screen Shot 2024-11-02 at 13.54.21](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/8/d8e9e321805add8d8b331a6a499e277c5d8d8788.png)  
 ![Screen Shot 2024-11-02 at 13.54.23](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/8/f88e40991fcdaeb751947ac8af8881b16601c1df.png)

Code I am using for consent:

show\_task = 1 #show everything

if ‘n’ in key\_resp\_3.keys: # Assuming ‘n’ is the key for ‘No’

show\_task = 0

and loop starts from at the end of consent to the at the end of experiment.

Hope its more clear now!

Thanks a lot!

Best regards,

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 2, 2024, 11:05am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/10 "2024-11-02T11:05:03Z")

</div>

I meant this part:

 ![Screen Shot 2024-11-02 at 14.04.22](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/5/c55cd289823d7c2c0e24952e73704358d74c5405.png)

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [November 2, 2024, 2:11pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/11 "2024-11-02T14:11:36Z")

</div>

Hello

The PsychoJS-part look ok.

Where and when do your use the consent routine? See the following example. this routine follows the consent routine. If ‘a’ is pressed the experiment ends.

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/4/249aac7de9634ae46ce872cc27bbc924dd91a496.jpeg)

Begin routine tab

```auto
if key_respGruss.keys != "a":
    continueRoutine = False

```

End routine tab

```auto
if key_respGruss.keys == "a":
    core.quit()

```

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 2, 2024, 6:43pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/12 "2024-11-02T18:43:43Z")

</div>

code\_both Begin Experiment is missing semi colons on the JS side.

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 4, 2024, 9:37am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/13 "2024-11-04T09:37:52Z")

</div>

hello, thanks a lot! Where exactly I should be adding semicolons? I am not familiar with js.

Thank you very much!

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 4, 2024, 9:39am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/14 "2024-11-04T09:39:42Z")

</div>

At the end of every line to separate one command from the next (as per the auto translated code).

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 4, 2024, 6:30pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/15 "2024-11-04T18:30:37Z")

</div>

am I missing something because I still get : ERROR invalid syntax (, line 1)

 ![Screen Shot 2024-11-04 at 21.28.56](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/f/bf811178052e2cf5af40db14d45f00bec0c07321.png)

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 4, 2024, 6:36pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/16 "2024-11-04T18:36:33Z")

</div>

Just changed to autoJS and still the same

 ![Screen Shot 2024-11-04 at 21.35.17](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/1/211173736bcfbe6c0d2a161e8e2b66ea7f84908d.png)  
error: ERROR invalid syntax (, line 1)

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [November 4, 2024, 6:56pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/17 "2024-11-04T18:56:44Z")

</div>

Hello, thanks so much for the quick response! Consent was the first routine. I was using  
if ‘y’ in key\_resp\_3.keys:  
show\_task = 1 #show everything  
if ‘n’ in key\_resp\_3.keys: # Assuming ‘n’ is the key for ‘No’  
show\_task = 0 # Exit the experiment if they do not consent  
In the end routine tab with loop starting at the end of consent through the end of the experiment.  
But I think there is a problem with this not translating to js? I also tried your version.Am I missing anything?

Thanks so much!  
Best regards,

 ![Screen Shot 2024-11-04 at 21.48.29](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/0/90e965ffafa1358704521117aa9499330d2badfb.png)  
 ![Screen Shot 2024-11-04 at 21.49.44](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/7/37f3f8f570ca772f8499812423c75a60e64f3ee4.png)

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [November 5, 2024, 8:31am UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/18 "2024-11-05T08:31:42Z")

</div>

Hello

This did not auto-translated.

```auto
if key_resp_3.keys == "n":
    core.quit()

```

It should translate to

```auto
if ((key_resp_3.keys === "n")) {
    core.quit();
}

```

Try resetting the **Code type** by switching to **Py** and back to **Auto-\> JS**. If this does not work, set the **Code type** to **both** and copy&paste the PsychoJS code to the PsychoJS side.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [December 9, 2024, 3:23pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/19 "2024-12-09T15:23:05Z")

</div>

Hello,  
I am trying to create a new project with same files. I am just pasting the routines from my working experiment to the new experiment. Though the old one was working now when I try to sync to pavlovia I get: ERROR invalid syntax (, line 1) When I inspect this is what I am seeing :

 ![Screenshot 2024-12-09 at 18.15.39](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/a/3ad437d609f4dc6f9d6734c5bca20326909274cc.jpeg)  
 ![Screenshot 2024-12-09 at 18.15.43](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/d/bdaabfdce445866fc1dabe671ea8868a8c08c270.jpeg)  
 ![Screenshot 2024-12-09 at 18.15.48](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/d/dd09aae785102146eba44d7b897dd13e00e60c4f.jpeg)

What could be the problem ?

Thank you very much

---

<div class="post-metadata">

**Author:** ![emilythom](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@emilythom](https://discourse.psychopy.org/u/emilythom)\
**Post date:** [December 9, 2024, 3:24pm UTC](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568/20 "2024-12-09T15:24:29Z")

</div>

Hello  
I am having the same problem with another project.  
I am trying to create a new project with same files. I am just pasting the routines from my working experiment to the new experiment. Though the old one was working now when I try to sync to pavlovia I get: ERROR invalid syntax (, line 1) When I inspect this is what I am seeing :

 ![Screenshot 2024-12-09 at 18.15.39](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/a/3ad437d609f4dc6f9d6734c5bca20326909274cc.jpeg)

 ![Screenshot 2024-12-09 at 18.15.43](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/d/bdaabfdce445866fc1dabe671ea8868a8c08c270.jpeg)

 ![Screenshot 2024-12-09 at 18.15.48](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/d/dd09aae785102146eba44d7b897dd13e00e60c4f.jpeg)

What could be the problem ?

Thank you very much!!!

[Next page](https://discourse.psychopy.org/t/js-syntax-error-invalid-syntax-unknown-line-1/42568.md?page=2)
