Let's have a deeper look at the working of traffic lights this week so that we can practice logic and loops. In the previous week we went into some different ways of representing a traffic light, now let's make the traffic light work. In traffic-light-1.js and traffic-light-2.js you will find the same requirements but with different ways of representing the traffic light. Have a look through the files and solve them.
- Which way of representing the traffic light did you find better? Why?
- What happens if you change the loop to a
do-whileloop instead of awhileloop? Why? - We could have also used a
forloop to make the traffic light do 2 full rotations. Do you think that would be better? Why or why not?