In: Computer Science
Write html code:
1. Define constructor functions Faculty and Course. An instance of Course has instance of Faculty as the value if its instructor instance variable.
Download testProb1.js and testProb1.html
Write two files (faculty.js and course.js)
Constructor function Faculty. Arguments name and dept; Instance variables, name (a string, with default ("name unknown")
Write get_ and set_ methods for both instance variables; toString() return strings of form "<name> of <dept>"
Constructor function Course Arguments name, times, instructorName, and instructorDept, all with string values
Instance variables name (a string, with default “unknown course name”)
times (a string, with default “unknown times”)
instructor (instance of Faculty, with no default), constructed using new and the Faculty constructor
Define get_ and set_ methods for all instance variables
setinstructor() takes an instance of Faculty as its parameter
getinstructor() returns an instance of Faculty
toString() returns the string value of the name instance variable
Please find the code below,
Faculty.js
class Faculty{
constructor(name = "name unknown", dept){
this._name = name
this._dept = dept
}
get name() {
return this._name;
}
set name(name) {
this._name = name;
}
get dept() {
return this._dept;
}
set dept(dept) {
this._dept = dept;
}
toString(){
return this._name+" of "+this._dept;
}
}
Course.js
class Course{
constructor(name = "unknown course name", times="unknown times",instructorName, instructorDept){
this._name = name
this._times = times
this._instructor = new Faculty(instructorName, instructorDept)
}
get name() {
return this._name;
}
set name(name) {
this._name = name;
}
get times() {
return this._times;
}
set times(times) {
this._times = times;
}
get instructor() {
return this._instructor;
}
set instructor(instructor) {
this._instructor = instructor;
}
toString(){
return this._name;
}
}
If you have any doubts feel free to ask in the comments. Also please do upvote the solution.