for-loops
Hi all,
This is not an urgent problem but just something I noticed. Not sure if it's my mistake or OS's.
I use two kinds of for-loops:
A: for (var i = 0; i < 10; i++) {
B: for (i of array) {
Both work fine in the browser. But when I try to run it within OS, version B trips it up: "SyntaxError: Line 6: Unexpected identifier"
I'm not sure but I got the feeling that while-loops also cause problems sometimes.
Cheers,
Jasper
Comments
Hi @JasperdeWaard ,
Is it possible to upload the script?
Cheers,
Lotje
Did you like my answer? Feel free to

Sure! For some reason it won't let me upload the latest version, but this should give you an idea.
In the 'vars' code block, the first function works fine, the second doesn't. The difference, I think, is in the kind of for-loop that they use.
Hi @JasperdeWaard ,
I think the version of JavaScript that OpenSesame uses is not the most recent, and that therefore, as you already guessed,
for of loops(in contrast tofor in loops?) are not supported.@sebastiaan , could you confirm this?
Cheers,
Lotje
Did you like my answer? Feel free to

In any case, the unexpected identifier that the error message is referring to seems to be the word "of"...
Did you like my answer? Feel free to

When running JavaScript on the desktop, OpenSesame uses js2py, which is compatible with ECMAScript 5.1 (where ECMAScript is the official JavaScript specification). The
for … of …syntax was introduced in ECMAScript 6, which is why it doesn't work on the desktop.This doesn't mean that you cannot use ECMAScript 6 syntax in an OSWeb experiment. It just means that, when you do, you can no longer run the experiment on the desktop.
Check out SigmundAI.eu for our OpenSesame AI assistant!
Alright, good to know!