Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2beedf4

Browse files
authored
Update traffic-light-2.js
1 parent 009bd90 commit 2beedf4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Week1/prep-exercises/1-traffic-light/traffic-light-2.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ let cycle = 0;
1313
while (cycle < 2) {
1414
const currentState = trafficLight.possibleStates[trafficLight.stateIndex];
1515
console.log("The traffic light is on", currentState);
16+
17+
if (currentState === "green") {
18+
trafficLight.stateIndex = 1; // Turn it orange
19+
} else if (currentState === "orange") {
20+
trafficLight.stateIndex = 2; // Turn it red
21+
} else if (currentState === "red") {
22+
cycle++; // Increment cycles
23+
trafficLight.stateIndex = 0; // Turn it green
24+
}
25+
}
1626

1727
// TODO
1828
// if the color is green, turn it orange

0 commit comments

Comments
 (0)