// src/App.jsx
function TrafficLight({ color }) {
const instructions = {
red: "Stop",
yellow: "Slow down",
green: "Go",
};
return
{instructions[color] ?? "Unknown signal"}
;
}
function App() {
return (
);
}
export default App;
/*
Notes:
- instructions[color] looks up the matching text by key — much
easier to extend (just add another key) than a chain of ternaries.
- ?? "Unknown signal" only kicks in when the lookup returns
undefined, i.e. when color isn't one of the three known keys —
as with the "purple" example above.
*/