Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

I am getting the correct output but the tests are still failing. Thanks for your help!

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

runSequence(config1, 2);

function generateTimeline(config, cycles) {
  let newArr = [];
  let counter = 0;
  for (let i = 1; i <= cycles; i++) {
    //console.log(i);
    for (let j = 0; j < config.phases.length; j++) {
      //console.log(config.phases[j].duration);
      counter += config.phases[j].duration;
      //console.log(counter);
      newArr.push(counter);
    }
  }
  return newArr;
}

//console.log(generateTimeline(config1, 1));

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

Hey @besaidaurochs07

There is no need to run the function runSequence, keep your logs clean and then try to submit.