Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec47026

Browse files
authored
Update traffic-light-1.js
changed the code to required output
1 parent 30024ba commit ec47026

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@
33
* The `state` property says what the traffic light's state (i.e. colour) is at
44
* that moment.
55
*/
6-
const trafficLight = {
6+
let trafficLight = {
77
state: "green",
88
};
99

1010
let rotations = 0;
1111
while (rotations < 2) {
1212
const currentState = trafficLight.state;
1313
console.log("The traffic light is on", currentState);
14-
14+
if(currentState == "green"){
15+
trafficLight.state = "orange";
16+
} else if(currentState == "orange"){
17+
trafficLight.state = "red";
18+
}else{
19+
rotations++;
20+
trafficLight.state = "green";
21+
}
1522
// TODO
1623
// if the color is green, turn it orange
1724
// if the color is orange, turn it red

0 commit comments

Comments
 (0)