The Cookie Has a Price چالش 2 از جلسهی 14، آسان
Food روی Item ساخته شده است. برنامه باید Cookie 20 150 را نشان بدهد، ولی خط قرمز دارد.
Run را بزن و بخوان چه فیلدی جا افتاده است. آن را با مقدار 20 به شیء snack اضافه کن (شکلها را عوض نکن).
<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;
}
interface Food extends Item {
calories: number;
}
const snack: Food = { name: "Cookie", calories: 150 };
show(snack.name, snack.price, snack.calories);
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 14: ساختن روی یک شکل · چالش بعدی: This and That
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js