JSFiddle - React, Tailwind, and code Playground
by Tim Morgan
JavaScript
/* Create an Employee and a Student class. Run greetAtGBC() against each of the classes. Your classes should have a constructor that takes a name */
function greetAtGBC(person) {
console.log("Hello " + person.name + "!");
if (person instanceof Employee) {
console.log("Your mailroom is A4-123");
} else if (person instanceof Student) {
console.log("How are your studies progressing?");
}
if( person instanceof Person ) {
console.log("All persons will see this message.");
}
else {
console.log("Why is a non-person going to this class?");
}
}
function Person() {}
Person.prototype.sayHi = function() { console.log("Hi!"); };
function Employee(name) { this.name = name; this.status = "Active"; this.salary="1234567";}
Employee.prototype = new Person();
Employee.prototype.hire = function() { this.status = "Active"; };
Employee.prototype.fire = function() { this.status = "Inactive"; };
function Student(name) { this.name = name; }
Student.prototype = new Person();
var me = new Employee("Joshua Koudys");
me.sayHi();
var student = new Student("Jimmy Neutron");
student.sayHi();
alert(student instanceof Person);
//greetAtGBC(me);
//greetAtGBC(student);