Skip to content

Commit 46b1b28

Browse files
committed
Completed traffic light exercise
1 parent c4a01c2 commit 46b1b28

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"use strict";
2-
/**
3-
* The `state` property says what the traffic light's state (i.e. colour) is at
4-
* that moment.
5-
*/
6-
const trafficLight = {
1+
let trafficLight = {
72
state: "green",
83
};
94

@@ -12,20 +7,14 @@ while (rotations < 2) {
127
const currentState = trafficLight.state;
138
console.log("The traffic light is on", currentState);
149

15-
// TODO
16-
// if the color is green, turn it orange
17-
// if the color is orange, turn it red
18-
// if the color is red, add 1 to rotations and turn it green
10+
if (currentState === "green") {
11+
trafficLight.state = "orange";
12+
}
13+
else if (currentState === "orange") {
14+
trafficLight.state = "red";
15+
}
16+
else if (currentState === "red") {
17+
trafficLight.state = "green";
18+
rotations++;
19+
}
1920
}
20-
21-
/**
22-
* The output should be:
23-
24-
The traffic light is on green
25-
The traffic light is on orange
26-
The traffic light is on red
27-
The traffic light is on green
28-
The traffic light is on orange
29-
The traffic light is on red
30-
31-
*/

0 commit comments

Comments
 (0)