freeCodeCamp icon indicating copy to clipboard operation
freeCodeCamp copied to clipboard

feat(curriculum): add traffic light sequencer lab

Open AdityaSingh-18 opened this issue 8 months ago • 5 comments

Checklist:

Closes #64122

This PR is part of Naomi's JS sprint to add lab traffic light sequencer to JS v9 loops.

Prototype: https://github.com/freeCodeCamp/CurriculumExpansion/pull/1147

AdityaSingh-18 avatar Mar 16 '26 17:03 AdityaSingh-18

Hi there,

Thanks for opening this pull request.

The linked issue is not open for contribution. If you are looking for issues to contribute to, please check out issues labeled help wanted or first timers only.


Join us in our chat room or our forum if you have any questions or need help with contributing.

github-actions[bot] avatar Mar 16 '26 17:03 github-actions[bot]

The runSequence solution can be modified slightly by adjusting the wording in the user stories and hints, so that the use of break and continue is no longer mandatory.

Ref: https://github.com/freeCodeCamp/CurriculumExpansion/pull/1147#pullrequestreview-3955213495

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 cycle = 1; cycle <= cycles; cycle++) {
        for (let i = 0; i < config.phases.length; i++) {
            let { color, duration } = config.phases[i];
            if (duration <= 0) {
                console.log("Invalid phase detected");
            }
            else {
                console.log(`Switching to ${color} for ${duration} s`);
            }
        }
    }
}

And we can remove the cycles parameter as well to avoid nested loops.

function runSequence(config) {
    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 < config.phases.length; i++) {
        let { color, duration } = config.phases[i];
        if (duration <= 0) {
            console.log("Invalid phase detected");
        }
        else {
            console.log(`Switching to ${color} for ${duration} s`);
        }
    }
}

AdityaSingh-18 avatar Mar 17 '26 06:03 AdityaSingh-18

@majestic-owl448 I had accepted your changes in the codespace while making changes and they are reflecting in the files as well I guess. I dont know why it's was still showing as required changes instead of outdated.

AdityaSingh-18 avatar May 18 '26 07:05 AdityaSingh-18

I know that sometimes the suggestions do that, so I checked the file and I was seeing the indentation was still not with 2 spaces

majestic-owl448 avatar May 19 '26 09:05 majestic-owl448

Hey @AdityaSingh-18, a few things still need to be addressed before this is ready.

1. generateTimeline user stories don't cover everything that's tested

Two behaviors are verified by the hints but not stated in the user stories:

  • generateTimeline(config3, 1) returns [5, 7, 13]: the fault flag is completely ignored. Nothing in the user stories tells learners that generateTimeline should not check for faults.
  • generateTimeline(config2, 2) returns [3, 1, 7, 10, 8, 14]: negative durations are accumulated as-is, so cumulative time can go backwards (3 → 1). The current user story says "record the cumulative elapsed time," which a learner might read as meaning they should skip invalid phases.

The user stories need a bullet that explicitly states that generateTimeline processes all phases without validation, including negative durations and faulted configs.

majestic-owl448 avatar May 28 '26 12:05 majestic-owl448