Skip to content

Commit a6f6c45

Browse files
committed
modified PrepEX
1 parent c4a01c2 commit a6f6c45

2 files changed

Lines changed: 16 additions & 33 deletions

File tree

Week1/prep-exercises/1-traffic-light/traffic-light-1.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,12 @@ while (rotations < 2) {
1212
const currentState = trafficLight.state;
1313
console.log("The traffic light is on", currentState);
1414

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
15+
if (currentState === "green") {
16+
trafficLight.state = "orange";
17+
} else if (currentState === "orange") {
18+
trafficLight.state = "red";
19+
} else {
20+
trafficLight.state = "green";
21+
rotations++;
22+
}
1923
}
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-
*/

Week1/prep-exercises/1-traffic-light/traffic-light-2.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@ let cycle = 0;
1313
while (cycle < 2) {
1414
const currentState = trafficLight.possibleStates[trafficLight.stateIndex];
1515
console.log("The traffic light is on", currentState);
16-
17-
// TODO
18-
// if the color is green, turn it orange
19-
// if the color is orange, turn it red
20-
// if the color is red, add 1 to cycles and turn it green
16+
if (currentState === "green") {
17+
trafficLight.stateIndex++;
18+
} else if (currentState === "orange") {
19+
trafficLight.stateIndex++;
20+
} else {
21+
trafficLight.stateIndex -= 2;
22+
cycle++;
23+
}
2124
}
22-
23-
/**
24-
* The output should be:
25-
26-
The traffic light is on green
27-
The traffic light is on orange
28-
The traffic light is on red
29-
The traffic light is on green
30-
The traffic light is on orange
31-
The traffic light is on red
32-
33-
*/

0 commit comments

Comments
 (0)