Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

The output seems fine in the console, but test shows runSequence function is not working as expected.

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){
  if(config.fault){
    console.log("Faulted phase!")
    return;
  }
  if(config.phases.length == 0){
    console.log("No phases found");
    return;
  }
  let phases = config.phases;
  for(let i=1;i<=cycles;i++){
    for(let j=0;j<phases.length;j++){
      if(phases[j].duration <= 0){
        console.log("Invalid phase detected");
      }else{
        console.log(`Switching to ${phases[j].color} for ${phases[j].duration} s`);
      }
    }
  }
}
function generateTimeline(config, cycles){
  let phases = config.phases;
  if(phases.length==0){
    return [];
  }
  let result = [];
  let sum = 0;
  for(let i=1;i<=cycles;i++){
    for(let j=0;j<phases.length;j++){
      sum = sum+phases[j].duration;
      result.push(sum);
    }
  }

  return result;
}
//console.log(generateTimeline(config2, 2));
runSequence(config2, 1)

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

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

This is resolved. Caused due to extra logs.