console.log("Hello, my name is Lydia!");
Hello, my name is Lydia!
var msg = "Hello, my name is Lydia!";
console.log(msg);
Hello, my name is Lydia!
Reuse of logIT
evalmachine.<anonymous>:5
logIt("Hello, Students!");
^

ReferenceError: logIt is not defined
    at evalmachine.<anonymous>:5:1
    at Script.runInThisContext (vm.js:96:20)
    at Object.runInThisContext (vm.js:303:38)
    at run ([eval]:1020:15)
    at onRunRequest ([eval]:864:18)
    at onMessage ([eval]:828:13)
    at process.emit (events.js:182:13)
    at emit (internal/child_process.js:812:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
function logIt(output) {
    console.log(output);
}
logIt(msg);
console.log("Reuse of logIT")
logIt("Mr. Yeung is so cool!");
logIt(2022)
Hello, my name is Lydia!
Reuse of logIT
Mr. Yeung is so cool!
2022
function logItType(output) {
    console.log(typeof output, ";", output);
}
console.log("This is the best class ever")
logItType("AP compsci"); 
logItType(2022);   
logItType([1, 2, 3]);
This is the best class ever
string ; AP compsci
number ; 2022
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); 
logItType(teacher);  
logItType(teacher.toJSON());  


teacher.setRole("Teacher");   
logItType(teacher); 
logItType(teacher.toJSON());
object ; Person { name: 'Mr M', ghID: 'jm1021', classOf: 1977, role: '' }
string ; {"name":"Mr M","ghID":"jm1021","classOf":1977,"role":""}
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("Lydia", "lydia-c2", 2024),
    new Person("Alexa", "alexac54767", 2024),
    new Person("Ava", "avac54765", 2024),
    new Person("Naja", "najaafoncesa", 2025),

];

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
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: 'Lydia',
    ghID: 'lydia-c2',
    classOf: 2024,
    role: 'Student' },
  Person {
    name: 'Alexa',
    ghID: 'alexac54767',
    classOf: 2024,
    role: 'Student' },
  Person { name: 'Ava', ghID: 'avac54765', classOf: 2024, role: 'Student' },
  Person {
    name: 'Naja',
    ghID: 'najaafoncesa',
    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() {
    // 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>" + "GitHub ID" + "</mark></th>";
    body += "<th><mark>" + "Class Of" + "</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.ghID + "</td>";
      body += "<td>" + row.classOf + "</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>
NameGitHub IDClass OfRole
Mr Mjm10211977Teacher
Lydialydia-c22024Student
Alexaalexac547672024Student
Avaavac547652024Student
Najanajaafoncesa2025Student