Menu
Coddy logo textTech

מערכת לניהול אוניברסיטה

חלק מהיחידה תכנות מונחה עצמים במסלול ה-JavaScript של Coddy. שיעור 55 מתוך 56.

challenge icon

אתגר

באתגר הזה יש לנו מערכת אוניברסיטאית עם סוגים שונים של אנשים (סטודנטים, פרופסורים), שלהם תפקידים והתנהגויות שונות.

1. השלימו את המחלקה Person:

  • הוסיפו את המתודה introduce() שמחזירה "Hi, I'm ${name}"

2. השלימו את המחלקה Student:

  • דרסו את introduce() כך שתחזיר ${super.introduce()}, a ${this.major} student. דוגמה: "Hi, I'm Alice, a Computer Science student"
  • הוסיפו את המתודה addGrade(grade), שמקבלת ציון בין 0 ל-100
    • אימות: בדקו אם הציון הוא בין 0 ל-100
    • אם הציון תקף: הוסיפו אותו למערך this.grades
    • אם הציון אינו תקף: רשמו ביומן: "Grade must be between 0 and 100"

3. השלימו את המחלקה Professor:

  • דרסו את introduce() כך שתחזיר “Prof. ${name} from ${department}”. דוגמה: “Prof. Smith from Computer Science”

נסו בעצמכם

import { Person } from './person.js';
import { Student } from './student.js';
import { Professor } from './professor.js';

// יצירת אנשים
const student1 = new Student('Alice', 20, 'Computer Science');
const prof1 = new Professor('Dr. Johnson', 50, 'Mathematics');

console.log(student1.introduce()); // "Hi, I'm Alice, a Computer Science student"
console.log(prof1.introduce())     // "Prof. Dr. Johnson from Mathematics"

student1.addGrade(85);
student1.addGrade(90);
student1.addGrade(95);
console.log(`${student1.name}'s GPA: ${student1.getGPA()}`); // ~3.6

student1.addGrade(105); // אמור להדפיס ללוג: "Grade must be between 0 and 100"

כל השיעורים ביחידה תכנות מונחה עצמים

תרגלו בעצמכם: קומפיילר JavaScript אונליין