diff --git a/Week1/prep-exercises/1-traffic-light/traffic-light-1.js b/Week1/prep-exercises/1-traffic-light/traffic-light-1.js index f1d9169..87a580d 100644 --- a/Week1/prep-exercises/1-traffic-light/traffic-light-1.js +++ b/Week1/prep-exercises/1-traffic-light/traffic-light-1.js @@ -11,6 +11,16 @@ let rotations = 0; while (rotations < 2) { const currentState = trafficLight.state; console.log("The traffic light is on", currentState); + + if (currentState === "green") { + trafficLight.state = "orange"; + } else if (currentState === "orange") { + trafficLight.state = "red"; + } else { + trafficLight.state = "green"; + rotations++; + } +} // TODO // if the color is green, turn it orange diff --git a/Week1/prep-exercises/1-traffic-light/traffic-light-2.js b/Week1/prep-exercises/1-traffic-light/traffic-light-2.js index 8c6ba95..26ee9a5 100644 --- a/Week1/prep-exercises/1-traffic-light/traffic-light-2.js +++ b/Week1/prep-exercises/1-traffic-light/traffic-light-2.js @@ -13,6 +13,16 @@ let cycle = 0; while (cycle < 2) { const currentState = trafficLight.possibleStates[trafficLight.stateIndex]; console.log("The traffic light is on", currentState); + + if (currentState === "green") { + trafficLight.stateIndex = 1; // Turn it orange + } else if (currentState === "orange") { + trafficLight.stateIndex = 2; // Turn it red + } else if (currentState === "red") { + cycle++; // Increment cycles + trafficLight.stateIndex = 0; // Turn it green + } +} // TODO // if the color is green, turn it orange