In the previous week we continued with our traffic light. Now that we also know what a function is we have one last look at the workings of a traffic light in a different way. Take a look at the traffic-light.js file and implement the same requirements as last week again, but then with another different way of organising.
- This time the loop was changed to a for loop that will run the code 6 times. Why was that needed?
- Why was the trafficLight added to the
mainfunction and not left at the top of the file? - What do you think is the advantage of having the
getCurrentTrafficLightStateandgetNextStateIndexfunctions?