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

جواب «Fix the Red Line» چالش 1 از جلسه‌ی 19

سؤال

b باید یک مستطیل ۳ در ۴ باشد. ولی کسی به آن radius داده، و مستطیل شعاع ندارد.
مقدار b را درست کن: width برابر 3 و height برابر 4. نوع‌ها را عوض نکن.
برنامه باید circle 2 و rect 12 را نشان بدهد.

راهنما

خط b این‌طور می‌شود: const b: Shape = { kind: "rect", width: 3, height: 4 };

یک جواب درست

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
#out { direction: ltr; text-align: left; font: 16px monospace; margin: 12px 0; padding: 12px; min-height: 28px; border-radius: 12px; background: #0f172a; color: #e2e8f0; white-space: pre-wrap; overflow-wrap: anywhere; }
#out .line { min-height: 22px; }
</style>

<pre id="out"></pre>

<script type="text/typescript">
interface Circle {
  kind: "circle";
  radius: number;
}

interface Rect {
  kind: "rect";
  width: number;
  height: number;
}

type Shape = Circle | Rect;

const a: Shape = { kind: "circle", radius: 2 };
const b: Shape = { kind: "rect", width: 3, height: 4 };
show(a.kind, a.radius);
show(b.kind, b.width * b.height);
</script>

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