Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

  1. You should not make changes in the config1, config2, config3, and config4 objects.
  2. runSequence(config1, 1) should log Switching to green for 5 s, Switching to yellow for 2 s, Switching to red for 4 s in order.
  3. runSequence(config1, 2) should log Switching to green for 5 s, Switching to yellow for 2 s, Switching to red for 4 s, Switching to green for 5 s, Switching to yellow for 2 s, Switching to red for 4 s in order.
  4. runSequence(config2, 1) should log Switching to red for 3 s, Invalid

Your code so far

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: 4 }
  ]
};

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

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

  for (let cycle = 0; cycle < cycles; cycle++) {
    if (config.fault === true) {
      console.log("Faulted phase!");
      return;
    }

    for (let phase of config.phases) {
      if (phase.duration <= 0) {
        console.log("Invalid phase detected");
      } else {
        console.log(`Switching to ${phase.color} for ${phase.duration} s`);
      }
    }
  }
}

runSequence(config1,1);

Your browser information:

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

Challenge Information:

Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-traffic-light-sequencer/69b83e35f19ba26ba1fa517a.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @purenepalgamer,

You have changed the starting code, which will cause the tests to fail.

To fix this, copy your function, reset the challenge, and paste your function back in below the “config” constants. Do not change those. Comment out your runSequence function call before running the tests again…then finish implementing the user stories.

Happy coding