Tell us what’s happening:
My solution/code passes all of the “this” should return “this” tests but for some reason, my code (that works) does not pass. I think the test running robot needs new batteries… Please help. Thanks.
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["fault"] === true) {
console.log("Faulted phase!");
return;
};
if (config.phases.length === 0) {
return console.log("No phases found");
};
for (let prop in config) {
if (prop === "phases") {
let cyclesCopy = cycles;
let count = cyclesCopy;
let phases = [...config["phases"]];
while (count > 0) {
for (let phase of phases) {
if ("duration" in phase && phase["duration"] <= 0) {
console.log("Invalid phase detected");
continue;
};
if ("duration" in phase && phase["duration"] > 0) {
let color = phase.color;
let duration = phase.duration;
console.log(`Switching to ${color} for ${duration} s`);
};
};
count--;
};
};
};
};
function generateTimeline(config, cycles) {
let cyclesCopy = cycles;
let count = cyclesCopy;
let configCopy = {...config};
let runningTotal = [];
for (let prop in configCopy) {
if (prop === "phases") {
let phases = [...configCopy["phases"]];
let total = 0;
while (count > 0) {
for (let phase of phases) {
let duration = phase.duration;
total = total + duration;
runningTotal.push(total);
};
count--
};
};
};
console.log(runningTotal);
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/152.0.0.0 Safari/537.36
Challenge Information:
Build a Traffic Light Sequencer - Build a Traffic Light Sequencer