console.log("Hello, World!");
Hello, World!
var msg = "Hello, World!";
console.log(msg);
Hello, World!
function logIt(output) {
    console.log(output);
}
logIt(msg);
Hello, World!
console.log("Reuse of logIT")
logIt("Hello, Students!");
logIt(2022)
Reuse of logIT
Hello, Students!
2022
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]);
Looking at dynamic nature of types in JavaScript
string ; hello
number ; 2020
object ; [ 1, 2, 3 ]
function Person(name, ghID, classOf) {
    this.name = name;
    this.ghID = ghID;
    this.classOf = classOf;
    this.role = "";
}


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

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


var teacher = new Person("Mr M", "jm1021", 1977);
teacher.setRole("Teacher");


logItType(teacher);  
logItType(teacher.toJSON());
object ; Person { name: 'Mr M', ghID: 'jm1021', classOf: 1977, role: 'Teacher' }
string ; {"name":"Mr M","ghID":"jm1021","classOf":1977,"role":"Teacher"}
var students = [ 
    new Person("Anthony", "tonyhieu", 2022),
    new Person("Bria", "B-G101", 2023),
    new Person("Allie", "xiaoa0", 2023),
    new Person("Tigran", "Tigran7", 2023),
    new Person("Rebecca", "Rebecca-123", 2023),
    new Person("Vidhi", "unknown", 2024),
    new Person ("Krishiv","Krishiv111", 2025)
];


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', classOf: 1977, role: 'Teacher' },
  Person {
    name: 'Anthony',
    ghID: 'tonyhieu',
    classOf: 2022,
    role: 'Student' },
  Person { name: 'Bria', ghID: 'B-G101', classOf: 2023, role: 'Student' },
  Person { name: 'Allie', ghID: 'xiaoa0', classOf: 2023, role: 'Student' },
  Person {
    name: 'Tigran',
    ghID: 'Tigran7',
    classOf: 2023,
    role: 'Student' },
  Person {
    name: 'Rebecca',
    ghID: 'Rebecca-123',
    classOf: 2023,
    role: 'Student' },
  Person { name: 'Vidhi', ghID: 'unknown', classOf: 2024, role: 'Student' },
  Person {
    name: 'Krishiv',
    ghID: 'Krishiv111',
    classOf: 2025,
    role: 'Student' } ]
string ; Mr M
string ; {"name":"Mr M","ghID":"jm1021","classOf":1977,"role":"Teacher"}
object ; { name: 'Mr M', ghID: 'jm1021', classOf: 1977, role: 'Teacher' }
Classroom.prototype._toHtml = function() {
    
    var style = (
      "display:inline-block;" +
      "background:blue;" +
      "border: 2px solid grey;" +
      "box-shadow: 0.8em 0.4em 0.4em grey;"
    );
  
    var body = "";
   
    body += "<tr>";
    body += "<th><mark>" + "Name" + "</mark></th>";
    body += "<th><mark>" + "GitHub ID" + "</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.ghID + "</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>
NameGitHub IDClass OfRole
Mr Mjm10211977Teacher
Anthonytonyhieu2022Student
BriaB-G1012023Student
Alliexiaoa02023Student
TigranTigran72023Student
RebeccaRebecca-1232023Student
Vidhiunknown2024Student
KrishivKrishiv1112025Student