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