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

Skip to content

Commit 64c7f03

Browse files
authored
Update traffic-light-2.js
edited code to required output
1 parent ec47026 commit 64c7f03

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ while (cycle < 2) {
1414
const currentState = trafficLight.possibleStates[trafficLight.stateIndex];
1515
console.log("The traffic light is on", currentState);
1616

17+
if(currentState == "green"){
18+
trafficLight.stateIndex ++;
19+
}else if(currentState == "orange") {
20+
trafficLight.stateIndex ++;
21+
}else{
22+
trafficLight.stateIndex -= 2;
23+
cycle++;
24+
}
1725
// TODO
1826
// if the color is green, turn it orange
1927
// if the color is orange, turn it red

0 commit comments

Comments
 (0)