Use conditionals to simulate traffic light behavior. Given a color, your program should tell a driver what action to take.
YOUR TASK
Create a program that:
Stores a traffic light color in a variable
Uses if / else if / else to check the color
Logs "Stop" for red
Logs "Wait" for yellow
Logs "Go" for green
Logs "Unknown color" for anything else
Need a hint?
Step-by-step:
1. const color = "red";
2. if (color === "red") {'{'} console.log("Stop"); {'}'}
3. else if (color === "yellow") {'{'} console.log("Wait"); {'}'}
4. else if (color === "green") {'{'} console.log("Go"); {'}'}
5. else {'{'} console.log("Unknown color"); {'}'}
Expected output (color = "red"):
Stop
Code Editor
Ready
Output
Console
Console initialized...
Ready for Project 2: Traffic Light Simulator
> Click "Run Code" to test your logic
> Click "Check My Code" to verify your solution