# trials.thisTrialN does not get correct trial number in javascript

**URL:** <https://discourse.psychopy.org/t/trials-thistrialn-does-not-get-correct-trial-number-in-javascript/13860>\
**Category:** Online experiments\
**Created:** [June 1, 2020, 8:23pm UTC](https://discourse.psychopy.org/t/trials-thistrialn-does-not-get-correct-trial-number-in-javascript/13860 "2020-06-01T20:23:59Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Miao](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/miao/32/3658_2.png) [@Miao](https://discourse.psychopy.org/u/Miao)\
**Post date:** [June 3, 2020, 2:51pm UTC](https://discourse.psychopy.org/t/trials-thistrialn-does-not-get-correct-trial-number-in-javascript/13860/15 "2020-06-03T14:51:19Z")

</div>

Hi @Tamer_Gezici,

I found a very tricky part of the JS logical judgment.

I used

```auto
if (window.MYTRIALN > 60 || window.MYTRIALN < 60){
    //alert('insideloop');
    continueRoutine = false;
}

```

And put it under Each Frames. The code works.

However, when I switched to

```auto
if (window.MYTRIALN != 60){
    //alert('insideloop');
    continueRoutine = false;
}

```

The code stopped working. Lol

I was also inlighted by [JavaScript - continueRoutine = false -- problem online](https://discourse.psychopy.org/t/javascript-continueroutine-false-problem-online/8669/4)

Therefore, I put it under each frame. Also, I initialized `window.MYTRIALN` as a global variable.

In sum, sort of working. Thank you so much.

Miao

---

_[View the full topic](https://discourse.psychopy.org/t/trials-thistrialn-does-not-get-correct-trial-number-in-javascript/13860)._
