Two Books چالش 2 از جلسهی 21، آسان
نقشهی Book آماده است، ولی هنوز هیچ کتابی از روی آن ساخته نشده.
۱. با new دو کتاب بساز: first با عنوان "Dune" و 300 صفحه، و second با عنوان "Momo" و 200 صفحه.
۲. هر کتاب را با یک show نشان بده: اول عنوان، بعد تعداد صفحه.
برنامه باید بنویسد: Dune 300 و در خط بعد Momo 200
<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">
class Book {
title: string;
pages: number;
constructor(title: string, pages: number) {
this.title = title;
this.pages = pages;
}
}
// build first and second here, then show them
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 21: کلاس با نوع · چالش بعدی: Types for the Counter
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js