# TypeError: core.CountdownTimer is not a constructor

**URL:** https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066
**Category:** Online experiments
**Tags:** pavlovia
**Created:** [April 6, 2021, 2:16pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066 "2021-04-06T14:16:21Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![hcheckeye](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@hcheckeye](https://discourse.psychopy.org/u/hcheckeye)
#### Post date: [April 6, 2021, 2:16pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/1 "2021-04-06T14:16:21Z")

</div>

URL of experiment: [https://run.pavlovia.org/wdstahlm/version-2](https://run.pavlovia.org/wdstahlm/version-2)

Description of the problem: I’m using a countdown timer to control the duration of a loop, and when I try piloting the experiment on Pavlovia, I am getting the following error: core.CountdownTimer is not a constructor. When I made the experiment, I used a code component to write this code and set it to Auto-\>JS. Anyone have any suggestions?

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [April 6, 2021, 4:19pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/2 "2021-04-06T16:19:02Z")

</div>

Please have a look at my code snippets for working with clocks.

> **[PsychoPy Code Component Snippets](https://docs.google.com/document/d/1kclYKgpbOCT3X8_O5pQOEIQHvD6zqMyxz3IKv3-K73I/edit#heading=h.2n0t84o7j31i)**
>
> PsychoPy version 2020.2.10Code Component Snippets Compiled by Wakefield Morys-Carter, Oxford Brookes UniversityPlease share widely and follow Psych\_Stats on twitter. Code components should be Auto Py-\>JS unless code has been added to the PsychoJS...

---

<div class="post-metadata">

### Author: ![hcheckeye](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@hcheckeye](https://discourse.psychopy.org/u/hcheckeye)
#### Post date: [April 6, 2021, 6:28pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/3 "2021-04-06T18:28:51Z")

</div>

Hi,

Thank you for the reply. I’m still a little confused, I used this countdown timer to end my loop, and I don’t see on this sheet a translation for the countdown timer code. I’ve included the auto-translated JS code below.

Begin Experiment:

```auto
countdownStarted = false;

```

Begin Routine:

```auto
if ((! countdownStarted)) {
    countdownClock = new core.CountdownTimer(600);
    countdownStarted = true;
}

```

Each frame:

```auto
timeRemaining = countdownClock.getTime();
if ((timeRemaining <= 0.0)) {
    continueRoutine = false;
    trials.finished = true;
    countdownStarted = false;
} else {
    minutes = Number.parseInt((timeRemaining / 60.0));
    seconds = Number.parseInt((timeRemaining - (minutes * 60.0)));
    timeText = ((minutes.toString() + ":") + seconds.toString());
}
```

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [April 6, 2021, 6:31pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/4 "2021-04-06T18:31:32Z")

</div>

Sorry I didn’t realise countdowntimer was its own thing. I’d recommend that you use define a clock which will work online

---

<div class="post-metadata">

### Author: ![hcheckeye](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@hcheckeye](https://discourse.psychopy.org/u/hcheckeye)
#### Post date: [April 6, 2021, 6:58pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/5 "2021-04-06T18:58:52Z")

</div>

So, I can use the core.clocks function and the translations you provided instead of the countdown timer, and simply write some code such that when the clock reaches a certain time, the trials loop is finished? I had a lot of issues with trying to create a temporal loop other ways in the past, so I’m hoping this would work.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [April 6, 2021, 7:14pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/6 "2021-04-06T19:14:27Z")

</div>

Correct, though quite a bit of my code snippet is about displaying the clock, which I’m not sure you need.

---

<div class="post-metadata">

### Author: ![hcheckeye](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@hcheckeye](https://discourse.psychopy.org/u/hcheckeye)
#### Post date: [April 7, 2021, 12:55am UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/7 "2021-04-07T00:55:29Z")

</div>

I do still want to display the time remaining, that’s why I was using the countdown timer, so I will have to find a way to display time remaining while still using the clock instead.

---

<div class="post-metadata">

### Author: ![hcheckeye](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@hcheckeye](https://discourse.psychopy.org/u/hcheckeye)
#### Post date: [April 7, 2021, 1:11am UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/8 "2021-04-07T01:11:45Z")

</div>

I was able to solve the construct error, however now I am getting an error that minutes are not defined. The python equivalent of the code ran fine from the builder. I have the following JS code in the each frame tab:

```auto
timeRunning = timerClock.getTime();
if ((timeRunning >= 600)) {
    continueRoutine = false;
    trials.finished = true;
    timerStarted = false;
} else {
    minutes = Number.parseInt(((600 - timeRunning) / 60.0));
    seconds = Number.parseInt(((600 - timeRunning) - (minutes * 60.0)));
    timeText = ((minutes.toString() + ":") + seconds.toString());
}

```

Do you have any advice? I apologize for so many questions, I don’t know JS at all!

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [April 7, 2021, 6:55am UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/9 "2021-04-07T06:55:51Z")

</div>

Put minutes = 0 and seconds =0 in Begin Experiment

---

<div class="post-metadata">

### Author: ![hcheckeye](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@hcheckeye](https://discourse.psychopy.org/u/hcheckeye)
#### Post date: [April 7, 2021, 3:03pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/10 "2021-04-07T15:03:48Z")

</div>

Worked! Thank you

---

<div class="post-metadata">

### Author: ![PsyTechMMU](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/psytechmmu/32/35713_2.png) [@PsyTechMMU](https://discourse.psychopy.org/u/PsyTechMMU)
#### Post date: [January 10, 2023, 10:31am UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/11 "2023-01-10T10:31:43Z")

</div>

I am running into this error myself now, but neither using `util.CountdownTimer();` [from PsychoJS](https://psychopy.github.io/psychojs/CountdownTimer.html) or switching to `new util.Clock();` alleviates the error, even though there appears to be no sign of the cited “core.CountdownTimer” in the JS code any more ([pavlovia experiment here](https://pavlovia.org/PsyTechMMU/mot_threeballs))…

Any help will be greatly appreciated! 🫠

---

<div class="post-metadata">

### Author: ![edithhaim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/edithhaim/32/37846_2.png) [@edithhaim](https://discourse.psychopy.org/u/edithhaim)
#### Post date: [April 18, 2023, 1:22pm UTC](https://discourse.psychopy.org/t/typeerror-core-countdowntimer-is-not-a-constructor/22066/12 "2023-04-18T13:22:21Z")

</div>

Hi, I encountered the same problem. You said you were able to solve the construct error, how did you do this?
