# Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

**URL:** <https://forum.freecodecamp.org/t/build-a-traffic-light-sequencer-build-a-traffic-light-sequencer/792330>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [June 25, 2026, 3:01pm UTC](https://forum.freecodecamp.org/t/build-a-traffic-light-sequencer-build-a-traffic-light-sequencer/792330 "2026-06-25T15:01:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adewalejohn900](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/adewalejohn900/32/379920_2.png) [@Adewalejohn900](https://forum.freecodecamp.org/u/Adewalejohn900)\
**Post date:** [June 25, 2026, 3:01pm UTC](https://forum.freecodecamp.org/t/build-a-traffic-light-sequencer-build-a-traffic-light-sequencer/792330/1 "2026-06-25T15:01:41Z")

</div>

### Tell us what’s happening:

Pls i cant sem to pass test 3,4,5,6,7 and 8 even though its returns what was required in the console

### Your code so far

```js
const config1 = {
  fault: false,
  phases: [
    { color: "green", duration: 5 },
    { color: "yellow", duration: 2 },
    { color: "red", duration: 4 }
  ]
};

const config2 = {
  fault: false,
  phases: [
    { color: "red", duration: 3 },
    { color: "yellow", duration: -2 },
    { color: "green", duration: 6 }
  ]
};

const config3 = {
  fault: true,
  phases: [
    { color: "green", duration: 5 },
    { color: "yellow", duration: 2 },
    { color: "red", duration: 6 }
  ]
};

const config4 = {
  fault: false,
  phases: []
};

function runSequence(config, cycles) {
  if (!config.phases || config.phases.length === 0) {
    console.log("No phases found");
    return;
  }

  let currentCycle = 1;

  while (currentCycle <= cycles) {
    
    for (let i = 0; i < config.phases.length; i++) {
      const phase = config.phases[i];

      if (config.fault === true) {
        console.log("Faulted phase!");
      }
      if (phase.duration <= 0) {
        console.log("Invalid phase detected");
      } else {
        console.log(`Switching to ${phase.color} for ${phase.duration} s`);
      }
    }

    currentCycle++;
  }
}

runSequence(config2, 1);

function generateTimeline (config, cycles) {
  const timeLine = [];
  let elaspedTime = 0;
  let currentCycle = 1;

  while (currentCycle <= cycles) {
    for (let i = 0; i < config.phases.length; i++) {
      const phase = config.phases[i];
      elaspedTime += phase.duration;
      timeLine.push(elaspedTime);
    }
    currentCycle++
  }
  return timeLine
}

```

### Your browser information:

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36`

### Challenge Information:

Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-v9/lab-traffic-light-sequencer/lab-traffic-light-sequencer)**
>
> Learn to Code — For Free

GitHub Link: [freeCodeCamp/curriculum/challenges/english/blocks/lab-traffic-light-sequencer/69b83e35f19ba26ba1fa517a.md at main · freeCodeCamp/freeCodeCamp · GitHub](https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/blocks/lab-traffic-light-sequencer/69b83e35f19ba26ba1fa517a.md)

---

<div class="post-metadata">

**Author:** ![dhess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dhess/32/406235_2.png) [@dhess](https://forum.freecodecamp.org/u/dhess)\
**Post date:** [June 25, 2026, 4:58pm UTC](https://forum.freecodecamp.org/t/build-a-traffic-light-sequencer-build-a-traffic-light-sequencer/792330/2 "2026-06-25T16:58:42Z")

</div>

Hi @Adewalejohn900,

> [@Adewalejohn900](#):
>
> ```auto
> if (config.fault === true) {
> console.log("Faulted phase!");
> }
> 
> ```

Why is this inside the loop? Did you need to use the loop variable here?

> - Log `Faulted phase!` and stop the simulation early if `config.fault` is set to `true`.

And why isn’t this instruction fully implemented?

Happy coding

---

<div class="post-metadata">

**Author:** ![Adewalejohn900](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/adewalejohn900/32/379920_2.png) [@Adewalejohn900](https://forum.freecodecamp.org/u/Adewalejohn900)\
**Post date:** [June 27, 2026, 10:04am UTC](https://forum.freecodecamp.org/t/build-a-traffic-light-sequencer-build-a-traffic-light-sequencer/792330/3 "2026-06-27T10:04:50Z")

</div>

Thank you very much for your response. I have passed all tests.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 25, 2026, 10:05am UTC](https://forum.freecodecamp.org/t/build-a-traffic-light-sequencer-build-a-traffic-light-sequencer/792330/4 "2026-07-25T10:05:40Z")

</div>

Closed on July 25, 2026, 10:05am UTC

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