Theme
Primary Color

تكليفات الدروس من [ 32 ] إلى [ 38 ]

[ 3 ] تكليفات على [ Class Part 2 And Generics ]

التكليف 01

  • لديك Abstract Class و Two Classes فيهم بعض المشاكل تحتاج للتعديل عليهم يتختفي الأخطاء
  • ممنوع إستخدام ال override Keyword
// Do Not Edit
type numandstring = number | string;

abstract class Game {
  constructor(public title: string, public price: numandstring) {}
  abstract getLocation() : string;
  abstract getDiscount() : string;
}

// Start Edit And Fix
class RPG extends Game {
  constructor(title: string, public price: numandstring, public rate: number) {
  }
}

class Action extends Game {
  constructor(title: string, public price: numandstring, public rate: number) {
  }
}
// End Edit And Fix

// Do Not Edit
let gameOne = new RPG("Ys", 100, 10);
let gameTwo = new Action("Uncharted", 90, 15, "Sony");

console.log(gameOne.title); // "Ys"
console.log(gameOne.price); // 100
console.log(gameOne.rate); // 10
console.log(gameOne.getDiscount()); // "Discount"
console.log(gameOne.getLocation()); // "Location"

console.log(gameTwo.title); // "Uncharted"
console.log(gameTwo.price); // 90
console.log(gameTwo.rate); // 15
console.log(gameTwo.company); // "Sony"
console.log(gameTwo.getDiscount()); // "Discount"
console.log(gameTwo.getLocation()); // "Location"

التكليف 02

  • لديك مجموعة من السطور تطبع قيم في ال Console
  • قم بكتابة ال Function لتعمل هذه السطور بدون أي مشكلة ويخرج ال Output كما في التعليقات
// Write Function Code Here

// Do Not Edit Here
console.log(showTypes()); // Nothing - Nothing - Nothing
console.log(showTypes<string>("String")); // String - Nothing - Nothing
console.log(showTypes<string, number>("String", 100)); // String - 100 - Nothing
console.log(showTypes<string, number, boolean>("String", 100, true)); // String - 100 - true
ملحوظة

إبحث عن Optional Generic Type

التكليف 03

  • لديك مجموعة من السطور تطبع قيم في ال Console
  • قم بكتابة ال Class لتعمل هذه السطور بدون أي مشكلة ويخرج ال Output كما في التعليقات

// Write Class Code Here

// Do Not Edit Here
let gameOne = new Game<string>("Ys", 100);
let gameTwo = new Game<number>(2064, 100); // There's A Game Called "2064"

console.log(gameOne.title); // "Ys"
console.log(gameOne.price); // 100
gameOne.getDiscount("50"); // "The Discount Is 50"

console.log(gameTwo.title); // 2064
console.log(gameTwo.price); // 100
gameTwo.getDiscount(80); // "The Discount Is 80"

حلول التكليفات

Premium

حلول التكليفات متاحة للأعضاء ال Premium

راجع الحلول وطور مهاراتك مع العضوية المميزة

اكتشف العضوية المميزة