Let's have a deeper look at the working of traffic lights this week so that we can practice logic and loops. 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 so you can see how the way we represent data affects the way we need to solve problems.
- Which way of representing the traffic light did you find better? Why?
- What happens if you change the loop to a
do-while
loop instead of awhile
loop? Why? - We could have also used a
for
loop to make the traffic light do 2 full rotations. Do you think that would be better? Why or why not?