function PrintType(output) { // function to output data type and data into terminal
    console.log(typeof output, ", ", output);
}
// define a function to hold data for a Person
function Person(name, age, residence) {
    this.name = name;
    this.age = age;
    this.residence = residence;
    this.role = "";
}

// define a setter for role in Person data
Person.prototype.setRole = function(role) {
    this.role = role;
}

// define a JSON conversion "method" associated with Person
Person.prototype.toJSON = function() {
    const obj = {name: this.name, age: this.age, residence: this.residence, role: this.role};
    const json = JSON.stringify(obj);
    return json;
}

// make a new Person and assign to variable student
var student = new Person("Ryan", 16, "SanDiego");  // object type is easy to work with in JavaScript
PrintType(student);  // before role
PrintType(student.toJSON());

// output of Object and JSON/string associated with student
student.setRole("Student");   // set the role
PrintType(student); 
PrintType(student.toJSON());
object ,  Person { name: 'Ryan', age: 16, residence: 'SanDiego', role: '' }
string ,  {"name":"Ryan","age":16,"residence":"SanDiego","role":""}
object ,  Person { name: 'Ryan', age: 16, residence: 'SanDiego', role: 'Student' }
string ,  {"name":"Ryan","age":16,"residence":"SanDiego","role":"Student"}
// define a student Array of Person(s)
var students = [ 
    new Person("Ryan", 16, "San Diego"),
    new Person("Josh", 16, "San Diego"),
    new Person("Eli", 16, "San Diego"),
    new Person("Jeffery", 17, "San Diego")
];
var teacher = new Person("Mr. M", "?", "San Diego")

// define a classroom and build Classroom objects and json
function Classroom(teacher, students){ // 1 teacher, many student
    // start Classroom with Teacher
    teacher.setRole("Teacher");
    this.teacher = teacher;
    this.classroom = [teacher];
    // add each Student to Classroom
    this.students = students;
    this.students.forEach(student => { student.setRole("Student"); this.classroom.push(student); });
    // build json/string format of Classroom
    this.json = [];
    this.classroom.forEach(person => this.json.push(person.toJSON()));
}

// make a CompSci classroom from formerly defined teacher and students
compsci = new Classroom(teacher, students);

// output of Objects and JSON in CompSci classroom
PrintType(compsci.classroom);  // constructed classroom object
PrintType(compsci.classroom[0].name);  // abstract 1st objects name
PrintType(compsci.json[0]);  // show json conversion of 1st object to string
PrintType(JSON.parse(compsci.json[0]));  // show JSON.parse inverse of JSON.stringify
object ,  [ Person {
    name: 'Mr. M',
    age: '?',
    residence: 'San Diego',
    role: 'Teacher' },
  Person { name: 'Ryan', age: 16, residence: 'San Diego', role: 'Student' },
  Person { name: 'Josh', age: 16, residence: 'San Diego', role: 'Student' },
  Person { name: 'Eli', age: 16, residence: 'San Diego', role: 'Student' },
  Person {
    name: 'Jeffery',
    age: 17,
    residence: 'San Diego',
    role: 'Student' } ]
string ,  Mr. M
string ,  {"name":"Mr. M","age":"?","residence":"San Diego","role":"Teacher"}
object ,  { name: 'Mr. M',
  age: '?',
  residence: 'San Diego',
  role: 'Teacher' }
// define an HTML conversion "method" associated with Classroom
Classroom.prototype._toHtml = function() {
    // HTML Style is build using inline structure
    var style = (
      "display:inline-block;" +
      "border: 2px solid grey;" +
      "box-shadow: 0.8em 0.4em 0.4em grey;"
    );
  
    // HTML Body of Table is build as a series of concatenations (+=)
    var body = "";
    // Heading for Array Columns
    body += "<tr>";
    body += "<th><mark>" + "Name" + "</mark></th>";
    body += "<th><mark>" + "Age" + "</mark></th>";
    body += "<th><mark>" + "Residence" + "</mark></th>";
    body += "<th><mark>" + "Role" + "</mark></th>";
    body += "</tr>";
    // Data of Array, iterate through each row of compsci.classroom 
    for (var row of compsci.classroom) {
      // tr for each row, a new line
      body += "<tr>";
      // td for each column of data
      body += "<td>" + row.name + "</td>";
      body += "<td>" + row.age + "</td>";
      body += "<td>" + row.residence + "</td>";
      body += "<td>" + row.role + "</td>";
      // tr to end line
      body += "<tr>";
    }
  
     // Build and HTML fragment of div, table, table body
    return (
      "<div style='" + style + "'>" +
        "<table>" +
          body +
        "</table>" +
      "</div>"
    );
  
  };
  
  // IJavaScript HTML processor receive parameter of defined HTML fragment
  $$.html(compsci._toHtml());
</table></div> </div> </div> </div> </div> </div> </div>
Name Age Residence Role
Mr. M ? San Diego Teacher
Ryan 16 San Diego Student
Josh 16 San Diego Student
Eli 16 San Diego Student
Jeffery 17 San Diego Student