diff --git a/src/students.ts b/src/students.ts index ac9d6c0..652866d 100644 --- a/src/students.ts +++ b/src/students.ts @@ -72,7 +72,7 @@ const students: Student[] = [ function getStudentName(student: Student): string { // write your code here... - return ""; // replace empty string with what you see is fit + return student.name; // replace empty string with what you see is fit } /** @@ -87,9 +87,12 @@ function getStudentName(student: Student): string { function getCourse(student: Student, courseIndex: number): string { // write your code here... - return ""; // replace empty string with what you see is fit + return student.courses[courseIndex]; // replace empty string with what you see is fit } +console.log(getStudentName(students[0])); +console.log(getCourse(students[4], 2)); + /** * `addCourseToStudent` function: * - Accepts: @@ -104,9 +107,13 @@ function getCourse(student: Student, courseIndex: number): string { function addCourseToStudent(student: Student, course: string): Student { // write your code here... + student.courses.push(course); return student; } +const updatedStudent = addCourseToStudent(students[7], "Physics"); +console.log(updatedStudent); + /** * `countCourses` function: * - Accepts a `student` parameter of type `Student`. @@ -117,9 +124,11 @@ function addCourseToStudent(student: Student, course: string): Student { function countCourses(student: Student): number { // write your code here... - return -1; // replace -1 with what you see is fit + return student.courses.length; } +console.log(countCourses(students[1])); + /** * `removeCourseFromStudent` function: * - Accepts: @@ -133,7 +142,11 @@ function countCourses(student: Student): number { */ function removeCourseFromStudent(student: Student, course: string): Student { // write your code here... + const courseIndex = student.courses.indexOf(course); + if (courseIndex !== -1) { + student.courses.splice(courseIndex, 1); + } return student; } @@ -156,7 +169,7 @@ function findStudentById( ): Student | undefined { // write your code here... - return undefined; // replace undefined with what you see is fit + return students.find((student) => student.id === studentId); // replace undefined with what you see is fit } export {