جواب «A Cat Is an Animal» چالش 1 از جلسهی 23
سؤال
برنامه یک Cat میسازد، ولی کلاس Cat هنوز نوشته نشده و خط قرمز میبینی.
کلاس Cat را بهعنوان فرزند Animal بنویس. لازم نیست چیزی داخلش باشد: همه چیز را از والد میگیرد.
برنامه باید بنویسد: Tom eats
راهنما
یک خط کافی است: class Cat extends Animal {}
یک جواب درست
<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 Animal {
constructor(public name: string) {}
eat(): string {
return this.name + " eats";
}
}
class Cat extends Animal {}
const cat = new Cat("Tom");
show(cat.eat());
</script>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن