File tree 1 file changed +28
-1
lines changed
Week1/prep-exercises/1-traffic-light
1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
1
"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
+ */
7
+ "use strict" ;
2
8
/**
3
9
* The `possibleStates` property define the states (in this case: colours)
4
10
* in which the traffic light can be.
@@ -16,9 +22,30 @@ while (cycle < 2) {
16
22
17
23
// TODO
18
24
// if the color is green, turn it orange
25
+ if ( currentState === "green" ) {
26
+ trafficLight . stateIndex = 1 ;
27
+ }
19
28
// if the color is orange, turn it red
20
- // if the color is red, add 1 to cycles and turn it green
29
+ else if ( currentState === "orange" ) {
30
+ trafficLight . stateIndex = 2 ;
31
+ }
32
+ // if the color is red, add 1 to rotations and turn it green
33
+ else {
34
+ trafficLight . stateIndex = 0 ;
35
+ cycle ++ ;
36
+ }
21
37
}
38
+ /**
39
+ * The output should be:
40
+
41
+ The traffic light is on green
42
+ The traffic light is on orange
43
+ The traffic light is on red
44
+ The traffic light is on green
45
+ The traffic light is on orange
46
+ The traffic light is on red
47
+
48
+ */
22
49
23
50
/**
24
51
* The output should be:
You can’t perform that action at this time.
0 commit comments