+ 1
why doesn't p5js work on sololearn website?
the codes I create in p5js library work only on the app version. it doesn't work on the website. When I run the code I get this error SyntaxError: Unexpected token '<' Anyone knows how to fix it? test the code below to see the problem. https://code.sololearn.com/W8a9A17A82A5/?ref=app
11 Respuestas
+ 3
You got three different issues, first to clear the syntax error you need to either delete or comment out line 11 of the HTML panel
Along the same vane to get rid of [TYPE html] in the top left corner of the output panel you need to delete or comment out line 6 of the HTML panel
Neither one of the issues above is stopping your code from running. The problem is that p5.js cannot find setup() or draw() in the global scope.
And the reason p5.js can't find setup() and draw() is because they are locally scoped to an anonymous function.
And the reason setup() and draw() are locally scope to an anonymous function is because when using playground via sololearn website anything in the js panel is wrap in an IIFE(Immediately Invoked Function Expression) at runtime.
One way to solve this is to add setup() and draw() to the global space.
https://code.sololearn.com/W6A9a20a18A1
Another alternative is use p5() constructor and create a separate namespace for the p5 sketches. This will help to avoid naming collisions
https://p5js.org/reference/#/p5/p5
+ 1
You can use the p5 remove() method, this should help keep your code running at its original pace.
https://code.sololearn.com/W4A16a11a9A1/?ref=app
https://code.sololearn.com/Wa12A13A14a4/?ref=app
0
I don't get the error. Seems like it's working to me.
0
you ran it from the browser?
0
provide an error string
0
what is error string?
I want to make sure the code runs on the website from a PC.
0
— "SyntaxError: Unexpected token '<'"
Line: ???
0
<head style="background-color:black"> 🤔
0
Vasiliy That is the problem. The line number doesn't show up, that is all what is written in the console when the code executes. This problem doesn't occur when I run the code from the app.
0
ODLNT Thanks a lot for the help. I ran the same code from the website, it works but it is completely slow and the same error message shows.
I might take this as an okay. The strange thing is that I used to run all my p5js codes on the website and they used to run just fine. but the past month or so they no longer work on the website, only on the phone.
0
Your code here...https://code.sololearn.com/WTSD5Q9Tub5D/?ref=app
And i just change the width and height in setup