File tree Expand file tree Collapse file tree
Week1/prep-exercises/1-traffic-light Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,20 +12,12 @@ while (rotations < 2) {
1212 const currentState = trafficLight . state ;
1313 console . log ( "The traffic light is on" , currentState ) ;
1414
15- // TODO
16- // if the color is green, turn it orange
17- // if the color is orange, turn it red
18- // if the color is red, add 1 to rotations and turn it green
15+ if ( currentState === "green" ) {
16+ trafficLight . state = "orange" ;
17+ } else if ( currentState === "orange" ) {
18+ trafficLight . state = "red" ;
19+ } else {
20+ trafficLight . state = "green" ;
21+ rotations ++ ;
22+ }
1923}
20-
21- /**
22- * The output should be:
23-
24- The traffic light is on green
25- The traffic light is on orange
26- The traffic light is on red
27- The traffic light is on green
28- The traffic light is on orange
29- The traffic light is on red
30-
31- */
Original file line number Diff line number Diff line change @@ -13,21 +13,12 @@ let cycle = 0;
1313while ( cycle < 2 ) {
1414 const currentState = trafficLight . possibleStates [ trafficLight . stateIndex ] ;
1515 console . log ( "The traffic light is on" , currentState ) ;
16-
17- // TODO
18- // if the color is green, turn it orange
19- // if the color is orange, turn it red
20- // if the color is red, add 1 to cycles and turn it green
16+ if ( currentState === "green" ) {
17+ trafficLight . stateIndex ++ ;
18+ } else if ( currentState === "orange" ) {
19+ trafficLight . stateIndex ++ ;
20+ } else {
21+ trafficLight . stateIndex -= 2 ;
22+ cycle ++ ;
23+ }
2124}
22-
23- /**
24- * The output should be:
25-
26- The traffic light is on green
27- The traffic light is on orange
28- The traffic light is on red
29- The traffic light is on green
30- The traffic light is on orange
31- The traffic light is on red
32-
33- */
You can’t perform that action at this time.
0 commit comments