File tree 1 file changed +6
-0
lines changed
Week2/prep-exercises/1-traffic-light 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
function getCurrentState ( trafficLight ) {
9
+ return trafficLight . possibleStates [ trafficLight . stateIndex ] ; // return the current state
9
10
// TODO
10
11
// Should return the current state (i.e. colour) of the `trafficLight`
11
12
// object passed as a parameter.
12
13
}
13
14
14
15
function getNextStateIndex ( trafficLight ) {
16
+ if ( trafficLight . stateIndex === trafficLight . possibleStates . length - 1 ) {
17
+ return 0 ; // If the current state is red(second index) return to the beginning (green)
18
+ } else {
19
+ return trafficLight . stateIndex + 1 ; // Otherwise increment the index to switch to next colour
20
+ }
15
21
// TODO
16
22
// Return the index of the next state of the `trafficLight` such that:
17
23
// - if the color is green, it will turn to orange
You can’t perform that action at this time.
0 commit comments