| Reference | Downloads | Github

Stimuli counter turns to NaN when online

Hi, I created an offline experiment with a counter that shows the number of the presented stimulus and the stimili left (like 12/96). It works fine offline, but when I push it online, the “NaN” is written where the counter was. What could be the reason for that? That’s my code:

Begin Experiment
counter = 1
total = 96

End Routine

In the Text Component
$"%d/%d" % (counter, total)

Hi @vanessa22, string formatting differs between Python and JavaScript, so the code above does not work online, and is why you are getting a NaN value. Try one of the following JS solutions:

newString = "" + counter + "/" + total // Just concatenate the numbers and strings
newString = `${counter} / ${total}` // Use string templates - note backticks are used, not single or double quotes

Hi @dvbridges , it worked - thanks! But, now the counter starts first to be displayed in the second trial. Any idea for that? That didn’t happen offline.

Do you mean, the counter is only presented after the first trial? Is your text component set to update after each repeat?

Yes, it appears only after the first trial. The text component is set to “set every repeat”.

Ok, not really sure what is happening without seeing the task, but you could manually set the text component in the Begin Routine tab:

texctCompName.text = `${counter} / ${total}`;

Unfortunately no changes with this