11"use strict" ;
2- /**
3- * The `possibleStates` property define the states (in this case: colours)
4- * in which the traffic light can be.
5- * The `stateIndex` property indicates which of the possible states is current.
6- */
2+
73const trafficLight = {
84 possibleStates : [ "green" , "orange" , "red" ] ,
95 stateIndex : 0 ,
@@ -14,20 +10,14 @@ while (cycle < 2) {
1410 const currentState = trafficLight . possibleStates [ trafficLight . stateIndex ] ;
1511 console . log ( "The traffic light is on" , currentState ) ;
1612
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
21- }
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
13+ if ( currentState === "green" )
14+ { trafficLight . stateIndex = 1 ;
15+ } else if ( currentState === "orange" )
16+ { trafficLight . stateIndex = 2 ;
3217
33- */
18+ } else if ( currentState === "red" ) {
19+ trafficLight . stateIndex = 0 ;
20+
21+ cycle ++ ;
22+ }
23+ }
0 commit comments