Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 051948c

Browse files
committed
prep exercises from week2 is completed
1 parent 4ed4f8c commit 051948c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77

88
function getCurrentState(trafficLight) {
99
// TODO
10+
return trafficLight.possibleStates[trafficLight.stateIndex];
1011
// Should return the current state (i.e. colour) of the `trafficLight`
1112
// object passed as a parameter.
1213
}
1314

1415
function getNextStateIndex(trafficLight) {
1516
// TODO
17+
if(trafficLight.stateIndex == 2){
18+
return 0;
19+
}else{
20+
return (trafficLight.stateIndex = trafficLight.stateIndex + 1);
21+
}
1622
// Return the index of the next state of the `trafficLight` such that:
1723
// - if the color is green, it will turn to orange
1824
// - if the color is orange, it will turn to red

0 commit comments

Comments
 (0)