بتل کد Battle Codeدارد باز می‌شود…

جواب «A Default Colour» چالش 4 از جلسه‌ی 7

سؤال

نشان Old رنگی نگرفته است. دو کار بکن:
1. در Badge به color مقدار پیش‌فرض "lightgray" بده.
2. در App یک نشان سوم با متن Lost و بدون رنگ اضافه کن.

راهنما

{ text, color = "lightgray" } و در App: <Badge text="Lost" />.

یک جواب درست

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.badge { display: inline-block; margin: 4px; padding: 4px 12px; border-radius: 999px; background: #bae6fd; }
.gold { color: goldenrod; }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
</style>

<div id="root" dir="ltr"></div>

<script type="text/jsx">
import { createRoot } from "react-dom/client";

function Badge({ text, color = "lightgray" }) {
  return <span className="badge" style={{ backgroundColor: color }}>{text}</span>;
}

function App() {
  return (
    <div id="badges" className="row">
      <Badge text="New" color="gold" />
      <Badge text="Old" />
      <Badge text="Lost" />
    </div>
  );
}

createRoot(document.getElementById("root")).render(<App />);
</script>

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن