Build a Traffic Light Squencer

Tell us what’s happening:

I’m stuck on step 4 which is confusing because when I run it it comes out fine? I even got rid of the console.logs because I thought that was screwing it up. Some help would be appreciated.

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 i = 0;
  const finalArray = [];
  while (i < cycles) {
    if (config.phases == []) {
      return "No phases found"
    };
    if (config.fault == true) {
      return "Faulted phase!"
    };

    for (let j = 0; j < config.phases.length; j++) {
      const color = config.phases[j].color;
      const duration = config.phases[j].duration;

      if (duration <= 0) {
        return "Invalid phase detected"
      };

      finalArray.push(`Switching to ${color} for ${duration} s`);
    }
    i++
    return finalArray.join(" ")
  }
}

Link to the project

Lesson URL (copy - paste from your browser’s address bar)

Hi @shawdowdancer14,

Please review User Story #3. What’s the first word in the first 4 bulleted items? Is that what you’re doing?

Happy coding