Skip to content

Commit 0115324

Browse files
committed
week two prep exercies
1 parent 0a2526f commit 0115324

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77

88
function getCurrentState(trafficLight) {
9+
910
// TODO
1011
// Should return the current state (i.e. colour) of the `trafficLight`
1112
// object passed as a parameter.
13+
return trafficLight.possibleStates[trafficLight.stateIndex];
1214
}
1315

1416
function getNextStateIndex(trafficLight) {
@@ -17,6 +19,7 @@ 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+
return (trafficLight.stateIndex + 1) % trafficLight.possibleStates.length;
2023
}
2124

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

0 commit comments

Comments
 (0)