Erro : Untaught SyntaxError: unexpected token 'var'

Hi, I’m trying to convert this code to JavaScript, but this error appears: “Untaught SyntaxError: unexpected token ‘var’”.

Converted code: https://www.openprocessing.org/sketch/839422/embed/

Original code: https://www.openprocessing.org/sketch/20105/embed/

Dont use class in P5JS. You need to convert class into javaScript functions.

I know that but isn’t it ES6 syntax? does P5JS support ES6 syntax? BTW I check he was getting error at

var [] tailPath;
which isn’t a JavaScript code. He is still using class defined in java structure.
it should be

var tailPath = [];

1st thing you’re gonna need is switch the engine from “Processingjs” to “P5js”.

Also read this wiki about transition from Processing’s Java Mode to p5js:

And the link below got many sketches w/ both Java Mode & p5js versions:

Have you seen the compatibility table for the class keyword?

Chrome since version 49 (42 under ´strict mode´).
Firefox since version 45. And so on.

Chrome v42 & v49 were released in 2015/Apr/14 & 2016/Mar/02 respectively:
https://en.wikipedia.org/wiki/Google_Chrome_version_history

While Firefox v45 was released in 2016/Mar/08:

So it has been about 4 years we have the class keyword available in major browsers!

p5js is a JS library. We can write ES6 code and use ES5 libraries w/ no worries.

Yeah, anyway. OP need to put a lot of effort to convert java code to JavaScript code for sure. Both of us not gonna do it for him. He better need to read the link provided by you and get to it. If returns with actual problem while implementing it then we can help him.

1 Like