Skip to content

Commit e8d371e

Browse files
committed
Completed the traffic-light exercise.
1 parent 3c6335f commit e8d371e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎Week2/prep-exercises/1-traffic-light/traffic-light.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function getCurrentState(trafficLight) {
99
// TODO
1010
// Should return the current state (i.e. colour) of the `trafficLight`
1111
// object passed as a parameter.
12+
13+
return trafficLight.possibleStates[trafficLight.stateIndex];
1214
}
1315

1416
function getNextStateIndex(trafficLight) {
@@ -17,6 +19,8 @@ function getNextStateIndex(trafficLight) {
1719
// - if the color is green, it will turn to orange
1820
// - if the color is orange, it will turn to red
1921
// - if the color is red, it will turn to green
22+
23+
return (trafficLight.stateIndex + 1) % trafficLight.possibleStates.length;
2024
}
2125

2226
// This function loops for the number of seconds specified by the `secs`

0 commit comments

Comments
 (0)