25+5 Clock Project - Test scripts failing on most timer tests

Hi FCC community,

For some reason, my clock is failing most timer related tests even though it functionally works as intended. I haven’t implemented all user stories yet but several should be passing.

Unfortunately the test suite is not very descriptive, all I see is

Script error. (:0)

For all the failing tests.

I hope it has nothing to do with my code which I think is sound, and as mentioned, I can see the clock work as intended on my browser (chrome).

Any help would be much appreciated. Please let me know what additional information you need to troubleshoot this.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:78.0) Gecko/20100101 Firefox/78.0

Challenge: Build a 25 + 5 Clock

Link to the challenge:

Many people make very similar statements in their posts. I’ve seen cases where the code actually look really good but somehow fail one or two tests. Even in such cases, the tests are not wrong. There were errors in the code. So I think people should not conclude “my work is perfect, why is it failing tests, there must be something wrong with the FCC tests” too soon. First, assume there’s something wrong with your code. I’m directing this opinion to the FCC community in general.

Now, back to your code. I looked at your code and found problems immediately. Here are some. When the clock is ticking, you should not be able to click the up and down buttons of the session and break length. But I can do that with your clock. When the clock reaches 00:00, it won’t stay for one second. The display immediately switches. The visual appearance of the clock is not a critical aspect of the project, but in your clock, the position of - and + changes when the length becomes less than 2 digits. This behavior is not just about User Interface. It affects the operation. I was clicking minus but when the display gets to 9, all of sudden I’m clicking plus.

In my opinion, your code is unnecessarily complex. For example

   this.setState(state => {
        const clock = state.sessionClock ? "sessionLength" : "breakLength";
		  let newClock = {}; 		
        const seconds = state[clock].sec==="00" ? "00" : parseInt(state[clock].sec);
        const minutes = state[clock].min;
			newClock[clock] = {
                    min: seconds.toString()==="00" && parseInt(minutes) >= 11 ? (parseInt(minutes)-1).toString() : seconds.toString()==="00" && parseInt(minutes) < 11 && parseInt(minutes) > 0 ? "0" + (parseInt(minutes)-1).toString(): minutes, 
                    sec: seconds.toString()==="00" && minutes.toString()==="00" ? "00" :
                    seconds.toString()==="00" ? "59" : seconds<11 ? "0" + (seconds-1).toString(): (seconds-1).toString()
		return newClock;

The code is very hard to read. It is very difficult to follow the logic, and therefore, very difficult to see if the code is correct or not. Why all these string conversion for testing? You’re putting too much logic inside the countdown function. Don’t mix the internal logic and the display. Why use strings like below?

      sessionLength : {
        min: "25",
        sec: "00"
      breakLength : {
        min: "5",
        sec: "00"
      sessCounterMin: "25",
      breakCounterMin: "5",
      sessionComplete: false,
		sessionClock: true

Just use a simple integer for sessionLength and breakLength.

All you really need to do is keep one state variable to track the time left. Decrement this variable every sec and check if the timer is up. If yes, then switch the clock (session to break and vice versa). If no, update the display. Something like this

countdown = () => {
      (prev) => ({timeLeft: prev.timeLeft - 1}),
      () => {
              if (this.state.timeLeft < 0) {
              } else {

The callback function is needed here because the setState method is asynchronous. You need to ensure that the timeLeft value has changed before switching the clock or update the display. The updateDisplayValue method will convert the timeLeft value to MM:SS format. This is only the place you want to deal with string conversion.
My recommendation is not to keep on debugging your current code, but step back to the design level and start from there.


I wasn’t implying the FCC tests were to blame and actually was under the assumption it was my code’s fault. Sorry I didn’t relay that properly.

I also never said my code was perfect, far from it as you just put it out for everyone.

I thought this forum was for beginners? Uncalled for response IMHO.

My understanding is the Forum is for everybody.

In my response, I’m just trying to be concise, precise, and direct. That may result in a harsher tone than intended.

You said this in your OP

I interpreted it as you believe your code is working perfectly when you state you think your code is sound and the clock is working as intended. In other words, you believe your code is meeting the specifications perfectly. The point I wanted to come across is don’t hope the test failures have nothing to do with your code. When there are test failures, expect it has everything to do with your code.

Although I stated that I was directing the opinion to the FCC community in general, I should not have included the first paragraph because it resulted in putting the focus away the main discussion point (code review). I should have put that first paragraph in a separate thread because it wasn’t a comment directed particularly to you.

1 Like

I should have verified what I originally posted.

Two points:

  • By sound I meant, I saw it visually ticking down, resetting, re-counting after pausing etc. The controls also seemed to be working as intended. Therefore I was confused why the test scripts did not encounter the same. Furthermore, the error messages given by the test suite were that the script failed - something I never saw before. Usually I get some sort of more detailed message as to why a particular test is failing. This doesn’t mean I automatically assumed the test suite was broken, no, I had serious doubts about my code. I know it is crappy and clunky and I hacked it with little design planning.

  • By no means was it a finished product and I thought I got that point across in my OP. I planned to get the countdown logic working before I fixed it up visually and I also knew that I was still able to switch the totals while it was running but had not got to that yet. The main point of my post, or so I thought, was that tests I thought should be passing, were not.

Regardless, last time I ever seek help on this forum - pretty vicious crowd. I thought FCC was all about helping beginners out, not humiliating them for a question they perceive is a slight against the automated tests.

Also, nice to see that two of the biggest moderators on this forum liked what was quite frankly your condescending and rude response to what I thought was an innocent question - nice “community” you have here.

Obviously you are unhappy in the manner I responded to your post. But what about the content? Do you think my review/assessment of your code is wrong or off the mark? Do you think your countDownSecs method is written well? Ignoring the messenger, do you think there’s any merit to the message?

I started participating on this forum perhaps since early April of this year. I posted a few questions and got help to fix the problem to pass the tests on a couple of projects. I review Forum threads to understand some of the common issues people faced when completing the projects. In return for the free learning and getting help from the Forum, I tried to help others by answering as many questions as I can. In this short period of several months, I find this Forum actually a “nice community”. There are hundreds of other participants here, so I hope you don’t reject this Forum because of my response to your post.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.