I am currently stuck on the runSequence function. I was somehow able to pass tests 4 and 5, but I made changes that disrupted the original pass. I am somehow getting the right outputs, but the undefined option and a phase object whose negative duration wasn’t omitted has disrupted any successful passes. I would appreciate some guidance to get back on the right track.
The reason undefined is coming because your function runSequence() doesn’t return anything. Also if you are already logging inside the function then there is no need to log the function again.
Also, you are iterating through the loop and checking config.phases === undefined and config.fault === true inside the loop. There is no point to go through these checks again and again because they are not part of phases and their value wont be changing.
And lastly, there is no need to check for this if(config.phases !== undefined), as you have already checked it above, you should directly console the statement if your phase is valid.
Thank you for your help so far! Only test case 8 for the runSequence function needs to be solved:. In the directions, I was a little confused at the second part of this step: Log No phases found and immediately return if config.phases is empty. I tried using return config or break, but somehow the test case does not resolve.
Finally, I am onto the generateTimeline function. For this function, I’m trying to understand one clear thing from the directions. Do I add a line of code to add the recursive sequence for the phase durations before pushing the result in, or is there a Math method that allows me to do this? The code below allows me to add each phase’s duration to the runningTotal array.
function runSequence(config, cycles) {
for(let i = 0; i < cycles; i++) {
if(config.fault === true) {
console.log("Faulted phase!")
break;
}
if(config.phases === undefined) {
console.log("No phases found")
}
if(config.phases !== undefined) {
for(const phase of config.phases) {
if(phase.duration <= 0) {
console.log("Invalid phase detected")
continue
}
else {
console.log(`Switching to ${phase.color} for ${phase.duration} s`)
}
}
}
}
}
function generateTimeline(config, cycles){
const runningTotal = []
for(let i = 0; i < cycles; i++) {
if(config.phases !== undefined || config.fault === true || duration <= 0) {
for(const phase of config.phases) {
runningTotal.push(phase.duration)
}
}
}
return runningTotal;
}