Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

The tests 4 through 8 are not passing, but when i run the code, it logs exactly what’s asked from the tests, so even if there’s something wrong, i can’t know.

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

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

const runSequence = (config, cycles) => {
  
  if (config.phases.length < 1) {
    console.log("No phases found")
      return;
    }
  if (config.fault === true) {
    console.log("Faulted phase!");
    return
}
  for (let i = 0; i < cycles; i++) {
    for (let j = 0; j < config.phases.length; j++) {
      if (config.phases[j].duration < 1) {
        console.log("Invalid phase detected")
      }
      else {console.log(`Switching to ${config.phases[j].color} for ${config.phases[j].duration} s`)}
    }
  }
}

const generateTimeline = (config, cycles) => {
  let phaseReg = [];
  let phaseCount = 0;

  for (let i = 0; i < cycles; i++) {
    for (let j = 0; j < config.phases.length; j++) {
      phaseCount += config.phases[j].duration;
      phaseReg.push(phaseCount)
    }
  }
  return phaseReg
}

runSequence(config4, 5)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0

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

Please remove this before you run the tests.

Oh my god, thanks i’m so stupid

You were able to code the correct solution to the workshop yourself, that doesn’t seem stupid at all it seems smart