Pomodoro #Timer Test 1 Failure: `Cannot read property '2' of null`

Hello All my tests pass except Timer test #1.
From what found in the test file: FCC Tests

What I know so far
It looks like the tester can’t find seconds at some point because it gets the second item in an array in line 28 of the tests file:

  function getSeconds(str) {
    return timerRe.exec(str)[2];

To double check, I passed this function a null and got the error: Cannot read property '2' of null, which matches what the test is giving me.

to try to catch the test failure in the act I created the following console log inside of my handleResetButtonClickFunction :

    const timerRe = new RegExp(/^(\d{2,4})[\.:,\/](\d{2})$/);
    console.log(`RESET BUTTON CLICK |--| innerText of SessionLen: ${document.getElementById('time-left').innerText}  | What the FCC tester is finding: ${timerRe.exec(document.getElementById('time-left').innerText)[2]}`)

Every output of this is a real number in the correct format, and each regex query goes off without a hitch (returning the seconds value every time ex: :02.

My assumption that the error stems from line 28 in the tester file may be incorrect…

Anyone have an idea what is going on?

I get the feeling it has to do with how you are dealing with minutes and seconds.

Personally, I found it easier to just use a Date and then format it using toISOString and substr. The only issue I had with that was with 60:00 as that is not how it works. 60 minutes is 1 hour, not 60 minutes. But I just returned the string 60:00 for that one case.


console.log(new Date(1500 * 1000).toISOString().substr(14, 5))
// 25:00

Here is the format function I used:

const formatTime = (time) => {
  // 3600 === 60 === 1 hour === 01:00:00 and not 00:60:00
  if (time === 3600) return '60:00';

  return new Date(time * 1000).toISOString().substr(14, 5);

But I do think you are right that it is the regex in the getSeconds function in the test that is throwing the error. Which seems to suggest it is not matching on two digits for the minutes/seconds

const timerRe = new RegExp(/^(\d{2,4})[\.:,\/](\d{2})$/);

function getSeconds(str) {
  return timerRe.exec(str)[2];

console.log(getSeconds('20:00')); // 00
console.log(getSeconds('0:00')); // Cannot read property '2' of null
console.log(getSeconds('00:0')); // Cannot read property '2' of null

BTW, I didn’t really look to see if it was intentional or not (to shorten the time it takes to test) but your timer is running too fast (it looks like 10 seconds is 1 second long).

1 Like

Alright, I figured it out. I was setting the time wrong. I was using :
This causes an issue when the session length is set to 1, not 01 for instance.

I fixed it by setting the time with the time string getter I wrote, and used in every other location where I set the time:


Thanks for your time! @lasjorg