Hello, my task was to make two constructors for the code that I also posted and they are not working. Can somebody help me figure out why they are not working. I posted them right below.
here are my constructors for course and Faculty
course.js:
function Course (name, times, instructorName, instructorDept ) {
this.name = name ||"unknown course name";
this.times = times||"unknown time";
this.instructor = new Faculty(instructorName, instructorDept);
this.getname = function();
this.setname = function( name );
this.gettimes = function();
this.settimes = function( dept );
this.getinstructor() = function();
this.setinstructor(Faculty);
this.name.toString = function();
}
faculty.js:
function Faculty(name, dept) {
this.name = name || "unknown";
this.dept = dept || "unknown";
this.getname = function();
this.setname = function( name );
this.getdata = function();
this.setdata = function( dept );
this.name.toString = function();
this.dept.toString = function();
}
Here is the test file testprob1.js:
var fac1 = new Faculty( "Dr. Smith", "Math" );
document.writeln( "New faculty: " + fac1.getname() + ", " + fac1.getdept() + "<br>" );
document.writeln( "Again: " + fac1 + "<br><br>" );
var fac2 = new Faculty();
document.writeln( "New faculty: " + fac2.getname() +
", " + fac2.getdept() + "<br>" );
fac2.setname( "Dr. Jones" );
fac2.setdept( "CS" );
document.writeln( "Updated: " + fac2.getname() +
" " + fac2.getdept() + "<br><br>" );
var crs1 = new Course( "COMP322", "MWF 1:00-1:50",
"Dr. Green", "CS" );
document.writeln( "New course: " + crs1.getname() +
", " + crs1.gettimes() +
", " + crs1.getinstructor() + "<br>" );
document.writeln( "Again: " + crs1 + "<br><br>" );
var crs2 = new Course();
document.writeln( "New course: " + crs2.getname() +
", " + crs2.gettimes() +
", " + crs2.getinstructor() + "<br><br>" );
crs2.setname( "COMP590" );
crs2.settimes( "TR 1:00-2:15" );
crs2.setinstructor( fac2 );
document.writeln( "Updated: " + crs2.getname() +
", " + crs2.gettimes() +
", " + crs2.getinstructor() );
The HTML drivers to run the code:
<html>
<head>
<title>Assignment 3, Problem 3</title>
<script type="text/javascript" src="faculty.js">
</script>
<script type="text/javascript" src="course.js">
</script>
<script type="text/javascript" src="testProb1.js">
</script>
</head>
</html>