Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

Anyone know why my code just doesn’t work? It keeps sending me error but apparenty my sintax is correct.

This is the lab:

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");
    return;
  }

  for (let i = 0; i < config.phases.length * cycles; i++) {
    const fase = config.phases[i % config.phases.length];

    if (config.fault === true) {
      console.log("Faulted phase!");
      break;
    }
    if (fase.duration <= 0) {
      console.log("Invalid phase detected");
      continue;
    }

    console.log(`Switching to ${fase.color} for ${fase.duration}`)
  }
}

function generateTimeline(config, cycles) {
  let duracion = 0;
  const array = []
  for (let i = 0; i < config.phases.length * cycles; i++) {
    const fase = config.phases[i % config.phases.length]
    duracion += fase.duration;
    array.push(duracion);

    return array;
  }
}

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

Please check to make sure your “Switching to…” log is logging exactly what is asked in the instructions:

Log Switching to [color] for [duration] s

Will the array you return from generateTimeLine ever have more than one item?

Happy coding