Menu
Coddy logo textTech

University Management System

Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 55 of 56.

challenge icon

Challenge

In this challenge, we have a university system with different types of people (students, professors) who have different roles and behaviors.

1. Complete Person class:

  • Add introduce() method returning "Hi, I'm ${name}"

2. Complete Student class:

  • Override introduce() to return ${super.introduce()}, a ${this.major} student. Example: "Hi, I'm Alice, a Computer Science student"
  • Add addGrade(grade) method that takes a grade between 0 and 100
    • Validation: Check if grade is between 0 and 100
    • If valid: Add to this.grades array
    • If invalid: Log: "Grade must be between 0 and 100"

3. Complete Professor class:

  • Override introduce() to return “Prof. ${name} from ${department}”. Example: “Prof. Smith from Computer Science”

Try it yourself

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

// Create people
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); // Should log: "Grade must be between 0 and 100"

All lessons in Object Oriented Programming