Skip to content

Commit c064546

Browse files
committed
update change
1 parent c4a01c2 commit c064546

File tree

2 files changed

+16
-35
lines changed

2 files changed

+16
-35
lines changed

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,12 @@ let rotations = 0;
1111
while (rotations < 2) {
1212
const currentState = trafficLight.state;
1313
console.log("The traffic light is on", currentState);
14-
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
1914
}
2015

21-
/**
22-
* The output should be:
16+
if (currentState === "green") { trafficLight.state = "orange";
2317

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
18+
} else if (currentState === "orange") { trafficLight.state = "red";
3019

31-
*/
20+
} else if (currentState === "red") { trafficLight.state = "green";
21+
rotations++;
22+
}
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
"use strict";
2-
/**
3-
* The `possibleStates` property define the states (in this case: colours)
4-
* in which the traffic light can be.
5-
* The `stateIndex` property indicates which of the possible states is current.
6-
*/
2+
73
const trafficLight = {
84
possibleStates: ["green", "orange", "red"],
95
stateIndex: 0,
@@ -14,20 +10,14 @@ while (cycle < 2) {
1410
const currentState = trafficLight.possibleStates[trafficLight.stateIndex];
1511
console.log("The traffic light is on", currentState);
1612

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
21-
}
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
13+
if (currentState === "green")
14+
{ trafficLight.stateIndex = 1;
15+
} else if (currentState === "orange")
16+
{ trafficLight.stateIndex = 2 ;
3217

33-
*/
18+
} else if (currentState === "red") {
19+
trafficLight.stateIndex = 0;
20+
21+
cycle++;
22+
}
23+
}

0 commit comments

Comments
 (0)