function logItType(output) {
    console.log(typeof output, ";", output);
}
console.log("Looking at dynamic nature of types in JavaScript")
logItType("hello");
logItType(2020);
logItType([1, 2, 3]);
function Person(name, ghID, scrum) {
    this.name = name;
    this.ghID = ghID;
    this.scrum = scrum;
    this.role = "";
}


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


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


var teacher = new Person("Mr M", "jm1021", "none");
logItType(teacher);
logItType(teacher.toJSON());  // ok to do this even though role is not yet defined


teacher.setRole("Teacher"); 
logItType(teacher); 
logItType(teacher.toJSON());
object ; Person { name: 'Mr M', ghID: 'jm1021', scrum: 'none', role: '' }
string ; {"name":"Mr M","ghID":"jm1021","scrum":"none","role":""}
object ; Person { name: 'Mr M', ghID: 'jm1021', scrum: 'none', role: 'Teacher' }
string ; {"name":"Mr M","ghID":"jm1021","scrum":"none","role":"Teacher"}
var students = [ 
    new Person("Sanika", "sanikasha", "Backend"),
    new Person("Noor", "Nope1013", "Frontend"),
    new Person("Shreya", "rey444", "Scrum Master"),
    new Person("Jiya", "jiya-sav", "Backend")
];


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', ghID: 'jm1021', scrum: 'none', role: 'Teacher' },
  Person {
    name: 'Sanika',
    ghID: 'sanikasha',
    scrum: 'Backend',
    role: 'Student' },
  Person {
    name: 'Noor',
    ghID: 'Nope1013',
    scrum: 'Frontend',
    role: 'Student' },
  Person {
    name: 'Shreya',
    ghID: 'rey444',
    scrum: 'Scrum Master',
    role: 'Student' },
  Person {
    name: 'Jiya',
    ghID: 'jiya-sav',
    scrum: 'Backend',
    role: 'Student' } ]
string ; Mr M
string ; {"name":"Mr M","ghID":"jm1021","scrum":"none","role":"Teacher"}
object ; { name: 'Mr M', ghID: 'jm1021', scrum: 'none', role: 'Teacher' }
Classroom.prototype._toHtml = function() {
  
    var style = (
      "display:inline-block;" +
      "background:green;" +
      "border: 2px solid grey;" +
      "box-shadow: 0.8em 0.4em 0.4em blue;"
    );
  
 
    var body = "";

    body += "<tr>";
    body += "<th><mark>" + "Name" + "</mark></th>";
    body += "<th><mark>" + "GitHub ID" + "</mark></th>";
    body += "<th><mark>" + "Scrum" + "</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.ghID + "</td>";
      body += "<td>" + row.scrum + "</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 GitHub ID Scrum Role
Mr M jm1021 none Teacher
Sanika sanikasha Backend Student
Noor Nope1013 Frontend Student
Shreya rey444 Scrum Master Student
Jiya jiya-sav Backend Student