function logItType(output) {
    console.log(typeof output, ";", output); //"typeof" keyword returns the type.
}
function Person(name, email, classOf) {
    this.name = name;
    this.email = email;
    this.classOf = classOf;
    this.role = "";
}

Person.prototype.setRole = function(role) {
    this.role = role;
}

Person.prototype.toJSON = function() {
    const obj = {name: this.name, ghID: this.email, classOf: this.classOf, role: this.role};
    const json = JSON.stringify(obj);
    return json;
}

// make a new Person and assign to variable teacher
var teacher = new Person("Mr M", "jmortensen@powayusd.com", 1977);  // object type is easy to work with in JavaScript
logItType(teacher);  // before role
logItType(teacher.toJSON());  // ok to do this even though role is not yet defined

// output of Object and JSON/string associated with Teacher
teacher.setRole("Teacher");   // set the role
logItType(teacher); 
logItType(teacher.toJSON());
object ; Person {
  name: 'Mr M',
  email: 'jmortensen@powayusd.com',
  classOf: 1977,
  role: '' }
string ; {"name":"Mr M","ghID":"jmortensen@powayusd.com","classOf":1977,"role":""}
object ; Person {
  name: 'Mr M',
  email: 'jmortensen@powayusd.com',
  classOf: 1977,
  role: 'Teacher' }
string ; {"name":"Mr M","ghID":"jmortensen@powayusd.com","classOf":1977,"role":"Teacher"}
var students = [ 
    new Person("Krishtopher Patil", "krishpatil1019@gmail.com", 2024),
    new Person("Donald Tran", "donqt15@gmail.com", 2024),
    new Person("Nathan Manangan", "prorichyman@gmail.com", 2024),
    new Person("Nicholas Ramos", "nicky.jay77@gmail.com", 2024),
];


function Classroom(teacher, students){ 

    teacher.setRole("Teacher");
    this.teacher = teacher;
    this.classroom = [teacher];

    this.students = students;
    this.students.forEach(student => { student.setRole("Student"); this.classroom.push(student); });

    this.json = [];
    this.classroom.forEach(person => this.json.push(person.toJSON()));
}


compsci = new Classroom(teacher, students);


logItType(compsci.classroom);  
logItType(compsci.classroom[0].name);  
logItType(compsci.json[0]);  
logItType(JSON.parse(compsci.json[0]));
object ; [ Person {
    name: 'Mr M',
    email: 'jmortensen@powayusd.com',
    classOf: 1977,
    role: 'Teacher' },
  Person {
    name: 'Krishtopher Patil',
    email: 'krishpatil1019@gmail.com',
    classOf: 2024,
    role: 'Student' },
  Person {
    name: 'Donald Tran',
    email: 'donqt15@gmail.com',
    classOf: 2024,
    role: 'Student' },
  Person {
    name: 'Nathan Manangan',
    email: 'prorichyman@gmail.com',
    classOf: 2024,
    role: 'Student' },
  Person {
    name: 'Nicholas Ramos',
    email: 'nicky.jay77@gmail.com',
    classOf: 2024,
    role: 'Student' } ]
string ; Mr M
string ; {"name":"Mr M","ghID":"jmortensen@powayusd.com","classOf":1977,"role":"Teacher"}
object ; { name: 'Mr M',
  ghID: 'jmortensen@powayusd.com',
  classOf: 1977,
  role: 'Teacher' }
Classroom.prototype._toHtml = function() {
    var style = (
      "display:inline-block;" +
      "border: 2px solid white;" +
      "box-shadow: 0.8em 0.4em 0.4em black;"
    );
  
    var body = "";
    
    body += "<tr>";
    body += "<th><mark>" + "Name" + "</mark></th>";
    body += "<th><mark>" + "Email" + "</mark></th>";
    body += "<th><mark>" + "Class Of" + "</mark></th>";
    body += "<th><mark>" + "Role" + "</mark></th>";
    body += "</tr>";

    for (var row of compsci.classroom) {

      body += "<tr>";

      body += "<td>" + row.name + "</td>";
      body += "<td>" + row.email + "</td>";
      body += "<td>" + row.classOf + "</td>";
      body += "<td>" + row.role + "</td>";
      body += "<tr>";
    }
  

    return (
      "<div style='" + style + "'>" +
        "<table>" +
          body +
        "</table>" +
      "</div>"
    );
  
  };
  

  $$.html(compsci._toHtml());
</table></div> </div> </div> </div> </div> </div> </div>
Name Email Class Of Role
Mr M jmortensen@powayusd.com 1977 Teacher
Krishtopher Patil krishpatil1019@gmail.com 2024 Student
Donald Tran donqt15@gmail.com 2024 Student
Nathan Manangan prorichyman@gmail.com 2024 Student
Nicholas Ramos nicky.jay77@gmail.com 2024 Student