Three Sizes چالش 2 از جلسهی 36، آسان
تابع price آماده است، ولی Size هنوز ساخته نشده و برای همین همه جا خط قرمز است.
بالای برنامه یک enum به اسم Size با سه عضو بساز: Small، Medium و Large.
برنامه باید 10 و بعد 20 را نشان بدهد.
<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">
// make the enum Size here
function price(size: Size): number {
if (size === Size.Small) {
return 10;
}
if (size === Size.Medium) {
return 15;
}
return 20;
}
show(price(Size.Small));
show(price(Size.Large));
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 36: مجموعههای اسمدار · چالش بعدی: Lock the Menu
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js