Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

I have the right answer but I can’t understand why would this not work?

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


function runSequence (config, cycles){
  let cycle = 0;
  let conPhases = config.phases;
while(cycle < cycles){
  let i = 0;
  while(i < conPhases.length){
  if (!config.phases || conPhases.length === 0){
    console.log("No phases found");
    return;
  } else if (config.fault === true){
    console.log("Faulted phase!");
    break;
  } else if (conPhases.duration <= 0){
    console.log("Invalid phase detected")
  } else {
    console.log(`Switching to ${conPhases.color} for ${conPhases.duration} s`)
  }
 }
 ++i
}
++cycle
};


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.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

Hi @Ruhollahbayani

Do you want one of the incrementors outsite the while loop?

Happy coding