Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

I am having trouble passing the 4, 5 and 6 tests. I used “,” for the logs separator before and I still got the same errors. I have three logs in the runSequence function.

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 counter = 0;
  const logs = [];
  let log;

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

    if(config.fault === true)
    {
      console.log("Faulted phase!");
      return;
    }

  while(counter < cycles)
  {
    for(const phase of config.phases)
    {
      if(phase['duration'] <= 0)
      {
        log = "Invalid phase detected";
        logs.push(log);
        continue;
      }
      log = `Switching to ${phase.color} for ${phase['duration']} s`;
      logs.push(log);   
    }
    console.log(logs.join("\n"));
    counter++;
  }
}

function generateTimeline(config, cycles){
  const timeStamps= [];
  let counter = 0;
  let temp = 0;
  while(counter < cycles)
  {
    for(const phase of config.phases)
    {
      temp += phase.duration;
     timeStamps.push(temp);
    }
    counter++;
  }
  return timeStamps;
}




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 @githuanjuguna,

Looking at Test #6, should your code stop processing if an invalid phase is detected?

Also, the tests are expecting a single log for each message.

Happy coding