From 009bd90a96f746f16a25925cb0d53d63ef1d7e6c Mon Sep 17 00:00:00 2001 From: bahram2024 <157040421+bahram2024@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:24:37 +0100 Subject: [PATCH 1/2] Update traffic-light-1.js --- .../prep-exercises/1-traffic-light/traffic-light-1.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 From 2beedf48d9c0805e385ca9515ece292c904f9d7c Mon Sep 17 00:00:00 2001 From: bahram2024 <157040421+bahram2024@users.noreply.github.com> Date: Sat, 27 Jan 2024 20:26:50 +0100 Subject: [PATCH 2/2] Update traffic-light-2.js --- .../prep-exercises/1-traffic-light/traffic-light-2.js | 10 ++++++++++ 1 file changed, 10 insertions(+) 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