Tell us what’s happening:
I independently tested the tests on my local environment and they run perfectly, but I cannot pass the same tests on the website. I’m encountering issues with tests 4-6 and 11-14.
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) {
console.log("Faulted phase!");
return;
}
for (let i = 0; i < cycles; i++){
for (elem of config.phases){
if (elem.duration <= 0) {
console.log("Invalid phase detected");
} else {
console.log(`Switching to ${elem.color} for ${elem.duration} s`);
}
}
}
}
function generateTimeline (config, cycles){
const counts = [];
let count = 0;
for (let i = 0; i < cycles; i++){
for (elem of config.phases){
count += elem.duration;
counts.push(count);
}
}
return counts;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Challenge Information:
Build a Traffic Light Sequencer - Build a Traffic Light Sequencer