Tell us what’s happening:
my code works accurately and i pass all the tests but it tell me to log the function and the answers should be in order and i log and it works just right but i have the error and i can’t pass . what should i do?
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 ;
}
for(let i=0 ; i<cycles; i++ ){
for(let j =0 ; j<config.phases.length ; j++){
const phase = config.phases[j];
if(phase.duration <=0){
console.log("Invalid phase detected");
return;
}else{
console.log (` Switching to ${phase.color} for ${phase.duration} s`);
}
}
}
}
function generateTimeline(config,cycles){
const cumulativeElapsed=[];
let runningTotal=0;
for(let i =0; i<cycles ; i++){
for(let j=0; j<config.phases.length; j++){
const phase = config.phases[j];
runningTotal += phase.duration;
cumulativeElapsed.push(runningTotal);
}
}
return cumulativeElapsed;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Challenge Information:
Build a Traffic Light Sequencer - Build a Traffic Light Sequencer