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

Step 2: The Shelf چالش 2 از جلسه‌ی 15، متوسط

قدم دوم: یک قفسه پر از کالا.
- به‌جای sword یک آرایه به اسم items با نوع Item[] بساز، با این سه کالا به همین ترتیب: Sword با قیمت 30، Shield با قیمت 45 و Potion با قیمت 10.
- خط‌های sword را پاک کن و با یک حلقه label هر کالا را نشان بده.
برنامه باید سه خط بنویسد: Sword: 30 coins، Shield: 45 coins و Potion: 10 coins.

<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 Item {
  name: string;
  price: number;
}

function label(item: Item): string {
  return item.name + ": " + item.price + " coins";
}

const sword: Item = { name: "Sword", price: 30 };
show(label(sword));
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 15: پروژه: فروشگاه بازی · چالش بعدی: Step 3: Total and Cheapest

بیشتر بخوان: جاوااسکریپت چیست؟ از دکمه‌ی وب تا Node.js