Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

I’m failing the tests except the ones requiring function decleration and parametres, pls 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) {
  for (let i = 0; i < cycles; i++) {
    if (config.phases === []) {
      console.log("No phases found")
      return
    } else if (config.fault == true) {
      console.log("Faulted phase!")
    } for (const phase of config.phases) {
      if (phase.duration <= 0) {
        console.log("Invalid phase detected")
      } else {
        console.log(`Switching to ${phase.color} for ${phase.duration} s`)
      }
    }
  }
}

function generateTimeline(config, cycles) {
  let arr = []
  for (let i = 0; i < cycles; i++) {
    let newun = config[phases].slice()
    config[phases].concat(newun)
  }
  for (let i = 0; i < config[phases].length * cycles; i++ ) {
    arr.push(config[phases][i][duration] + config[phases][i + 1][duration])
  }
  return arr
}

console.log(runSequence(config1, 1))
console.log(generateTimeline(config3, 1))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 OPR/134.0.0.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

Hi @subhanowaiskhan,

Do you need to be in a loop for this code? Should processing continue if it’s a faulted phase?

Happy coding