Tell us what’s happening:
I can’t pass test 4 to 8, but everything works perfectly. Where did I go wrong, PLEASE 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) {
if(config.phases.length === 0){
console.log("No phases found");
return;
}
if(config.fault === true){
console.log("Faulted phase!");
return;
}
let count = 0;
while(count < cycles){
for(let i = 0; i < config.phases.length; i++){
if(config.phases[i].duration <= 0){
console.log("Invalid phase detected");
return;
}else{
let dur = config.phases[i].duration;
let col =config.phases[i].color;
console.log(`Switching to ${col} for ${dur} s`);
}
}
count++
}
}
runSequence(config1, 1);
// function generateTimeline(config, cycle) {
// }
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Build a Traffic Light Sequencer - Build a Traffic Light Sequencer