Theme
Primary Color

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

[ 7 ] تكليفات على [ Interfaces & Class Part 1 ]

التكليف 01

  • لدينا Interface بإسم Member يمكنك التعديل عليه كما تريد
  • قم بالتعديل على ال Interface لتنتهي رسائل الخطأ الموجودة في ال Object بالأسفل
  • ممنوع التعديل عى ال Object ولا السطور الموجودة تحته
  • لديك 4 أخطاء كل واحد فيه التعليق الذي يعبر عنه

// Edit The Interface To Fix The Problems
interface Member {
  id: number;
  username: string;
  country: string;
  readonly state: boolean;
}

// Do Not Edit The Code Below
let user: Member = { // Property 'country' is missing in type
  id: 100,
  username: "Elzero",
  state: true,
  getName() { // 'getName' does not exist in type 'Member'
    return this.username;
  }
}

user.id = 200;
user.id = "200"; // Type 'string' is not assignable to type 'number'
user.state = false; // Cannot assign to 'state' because it is a read-only property

التكليف 02

  • لدينا ال Object التالي لا تقم بالتعديل عليه
  • قم بإنشاء ال Interface لنطبع بيانات ال Object بنجاح

// Create Interface Here

// Do Not Edit The Code Below
let client: Client = {
  id: 100,
  username: "Elzero",
  active: true,
  discount: 10,
  getPrice(price: number) {
    return price - this.discount;
  }
}

console.log(`Client Id Is ${client.id}`);
console.log(`Client Name Is ${client.username}`);
console.log(`Client Has Dicount ${client.discount}`);
console.log(`Client Product After Discount Is ${client.getPrice(200)}`);

التكليف 03

  • لدينا ال Object التالي لا تقم بالتعديل عليه
  • لدينا أيضا إثنين Interfaces لا تقم بالتعديل عليهم
  • إستخدم ما تعلمته مع عدم تكرار الخواص الموجودة داخل ال Interface لتجعل ال Object جاهز لطباعة محتواه

// Do Not Edit The Code Below
interface Man {
  title: string;
  weight: number;
  age: number;
}

interface Bird {
  canFly: boolean;
}

let creature: Superman = {
  title: "Superman",
  weight: 100,
  age: 500,
  canFly: true,
  bodyType: "Iron",
  origin: "Krypton"
}

التكليف 04

  • لديك ال Objects التالية ونحتاج لإنشاء ال Class الذي ينشيء هذه ال Objects
  • يجب إستعمال ال Type Annotations مع ال Class Members
  • ممنوع نهائيا إستخدام ال Any Type

// Create Class Here

// Do Not Edit The Code Below
let player1 = new Player("Osama", "Mage", 90, true);
let player2 = new Player("Shady", "Archer", "85", false);
let player3 = new Player("Amr", "Fighter", 50, true);
let player4 = new Player("Mahmoud", "Assassin", 77);

console.log(player1.details()); // VIP Osama, Type Is Mage Level Is 90
console.log(player2.details()); // Shady, Type Is Archer Level Is 85
console.log(player3.details()); // VIP Amr, Type Is Fighter Level Is 50
console.log(player4.details()); // Mahmoud, Type Is Assassin Level Is 77

التكليف 05

  • لديك ال Class التالي
  • نريد إختصار ال Code تماما

class Shorten {
  public id: number;
  public username: string;
  protected title: string;
  constructor (id: number, username: string, title: string) {
    this.id = id;
    this.username = username;
    this.title = title;
  }
}

let tester = new Shorten(100, "Elzero", "Developer");

console.log(tester.id);
console.log(tester.username);

التكليف 06

  • لديك ال Class التالي
  • نريد تصليح الأخطاء وطباعة القيمة الخاصة بال Title بدون تغيير حالة ال Private الموجودة في ال Class Member

class Show {
  constructor (private _title: string) {}
}

let tester = new Show("Elzero");

console.log(tester.title); // Property 'title' does not exist on type 'Show'
tester.title = "Osama"; // Property 'title' does not exist on type 'Show'
console.log(tester.title); // Property 'title' does not exist on type 'Show'
class Show {
  constructor (private _title: string) {}
  // get title(): string {
  //   return this._title;
  // }
  // set title(val: string) {
  //   this._title = val;
  // }
}

let tester = new Show("Elzero");

console.log(tester.title); // Property 'title' does not exist on type 'Show'
tester.title = "Osama"; // Property 'title' does not exist on type 'Show'
console.log(tester.title); // Property 'title' does not exist on type 'Show'

التكليف 07

  • لديك ال Interface التالي
  • قم بإنشاء Class يقوم بعمل Implement لهذا ال Interface
  • مع ضمان ظهور البيانات كما في التعليق

interface Play {
  id: number;
  title: string;
  level: number | string;
  logIn(): void;
  logOut(msg: string): void;
}

// Create Your Class Here

let player1 = new Player(100, "Elzero", 95);

console.log(player1.id); // 100
console.log(player1.title); // "Elzero"
console.log(player1.level); // 95
player1.logIn(); // Logged In
player1.logOut("Good Bye"); // Logged Out, Good Bye

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

Premium

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

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

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