3
04/11/2024 6:33 am
Topic starter
Write a JS class Person and a class Teacher which extends Person. A Person should have a name and an email. A Teacher should have a name, an email, and a subject.
Input
There will be no input.
Output
Your function should return an object containing the classes Person and Teacher.
Example:
function personAndTeacher() {
//TODO
return {
Person,
Teacher
}
}
1 Answer
2
04/11/2024 6:35 am
The solution:
function solve() {
class Person {
constructor(name, email) {
this.name = name;
this.email = email;
}
}
class Teacher extends Person {
constructor(teacherName, teacherEmail, subject) {
super(teacherName, teacherEmail);
this.subject = subject;
}
}
return {
Person,
Teacher
}
}
let teacher = new Teacher("Ivan", "ivan@ivan.bg", "history");
console.log(teacher);
