|
1 | 1 | "use strict";
|
2 | 2 | /**
|
3 |
| - * The `state` property says what the traffic light's state (i.e. colour) is at |
| 3 | + * The `state` property says what the traffic light's state (i.e. color) is at |
4 | 4 | * that moment.
|
5 | 5 | */
|
6 | 6 | const trafficLight = {
|
7 |
| - state: "green", |
| 7 | + state: "green", |
8 | 8 | };
|
9 | 9 |
|
10 | 10 | let rotations = 0;
|
11 | 11 | while (rotations < 2) {
|
12 |
| - let currentState = trafficLight.state; |
13 |
| - console.log("The traffic light is on", currentState); |
| 12 | + const currentState = trafficLight.state; |
| 13 | + console.log("The traffic light is on", currentState); |
14 | 14 |
|
15 |
| - // TODO |
16 |
| - // if the color is green, turn it orange |
17 |
| - if (currentState === "green") { |
18 |
| - trafficLight.state = "orange"; |
19 |
| - } |
20 |
| - // if the color is orange, turn it red |
21 |
| - else if (currentState === "orange") { |
22 |
| - trafficLight.state = "red"; |
23 |
| - } |
24 |
| - // if the color is red, add 1 to rotations and turn it green |
25 |
| - else { |
26 |
| - trafficLight.state = "green"; |
27 |
| - rotations++; |
28 |
| - } |
| 15 | + // TODO |
| 16 | + // if the color is green, turn it orange |
| 17 | + if (currentState === "green") { |
| 18 | + trafficLight.state = "orange"; |
| 19 | + } |
| 20 | + // if the color is orange, turn it red |
| 21 | + else if (currentState === "orange") { |
| 22 | + trafficLight.state = "red"; |
| 23 | + } |
| 24 | + // if the color is red, add 1 to rotations and turn it green |
| 25 | + else { |
| 26 | + trafficLight.state = "green"; |
| 27 | + rotations++; |
| 28 | + } |
29 | 29 | }
|
30 | 30 |
|
31 | 31 | /**
|
|
0 commit comments