Student Course Enrollment System

Oct 29, 2023


Your goal is to create a TypeScript program for managing student course enrollments. The program should allow students to enroll in courses, view their enrolled courses, and check for course prerequisites.


  1. Create a class calledCoursethat represents a course. Each course should have the following properties:

    • id(a unique course ID).

    • name(course name).

    • enrolledStudents(an array to store the students enrolled in the course).

    • prerequisites(an array of course IDs that are prerequisites for this course).

  2. Create a class calledStudentthat represents a student. Each student should have the following properties:

    • id(a unique student ID).

    • name(student name).

    • enrolledCourses(an array to store the courses in which the student is enrolled).

  3. Implement a function calledenrollStudentInCoursethat takes a student ID and a course ID as parameters. The function should enroll the student in the specified course if all prerequisites are met. If any prerequisites are not met, display an error message.

  4. Implement a function calledviewEnrolledCoursesthat takes a student ID as a parameter and displays the names of the courses in which the student is enrolled.

  5. Implement a function calledcheckPrerequisitesthat takes a course ID as a parameter and displays the names of the courses that are prerequisites for the specified course.

Example Usage:

const course1 = new Course(1, "Math 101", [2, 3], [4]);
const course2 = new Course(2, "Physics 101", [], []);
const course3 = new Course(3, "Chemistry 101", [2], []);

const student1 = new Student(1, "Alice");
const student2 = new Student(2, "Bob");

// Enroll students in courses
enrollStudentInCourse(student1, course1); // Should display an error message about missing prerequisites.
enrollStudentInCourse(student1, course2); // Should enroll Alice in Physics 101.
enrollStudentInCourse(student2, course3); // Should enroll Bob in Chemistry 101.

// View enrolled courses
viewEnrolledCourses(student1); // Should display "Enrolled courses for Alice: Physics 101"
viewEnrolledCourses(student2); // Should display "Enrolled courses for Bob: Chemistry 101"

// Check prerequisites
checkPrerequisites(course1); // Should display "Prerequisites for Math 101: Physics 101, Chemistry 101"

Acceptance criteria
  • use ES6 classes to declare Course and Student objects

  • Validate parameter types (don't rely on TS checks only)

Fork the Code Sandbox, do notupdateit in the website here, because Code Sandbox doesn't recognize you unless you open it in the website.
Supports markdown syntax.
You can submit your answer only once, so make sure you have the correct answer before submitting.