Build a Traffic Light Sequencer - Build a Traffic Light Sequencer

Tell us what’s happening:

What is my code not working it 's not checked but the out put is correct

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

console.log(runSequence(config1, 2));



Your browser information:

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

Welcome to the forum @getalemayhu,

Please review again User Story #3. You are not following the directions.

Where were you asked to create a message variable? What’s the first word in each of those bulleted items? Where are you doing that?

Also, before running the tests, please comment out your call to runSequence to comply with the “Note” in the instructions.

Happy coding

Thanks for your helpful response!