Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

I cannot pass tests 4, 5, 6, 7, and 8 even though runSequence accomplishes the tasks. What am I doing wrong here?

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 firstCyc = 0;

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

runSequence(config1, 1)

function generateTimeline(config, cycles) {
  const time = [];
  let elapsed = 0;

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3.1 Safari/605.1.15

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

Let’s try solving this issue together; one test case at a time. We’ll start with the fourth test case.

runSequence(config1, 1) should log Switching to green for 5 s, Switching to yellow for 2 s, Switching to red for 4 s in order.

Can you run the runSequence(config1, 1) function and tell me what it outputs to the console right now?

Switching to green for 5 s
Switching to yellow for 2 s
Switching to red for 4 s

Check this note:

Note: Do not add any extra console.log() statements, as they may cause the tests to fail.

Once you have tested your code, remove any log statements that you’ve used to test.

Thank you. I did not think that calling a function was the same as logging to console.

Can a mod please delete my post? So the answer isn’t given out to others