console.log("Nicolas' JavaScript practice");

function logItType(output) {
    console.log(typeof output, ";", output);
}

// define a function to hold data for a Person
function Person(name, peergrade, role) {
    this.name = name;
    this.peergrade = peergrade;
    this.role = role;
}

// define a JSON conversion "method" associated with Person
Person.prototype.toJSON = function() {
    const obj = {name: this.name, peergrade: this.peergrade, role: this.role};
    const json = JSON.stringify(obj);  // json/string is useful when passing data on internet
    return json;
}

// make a new Person and assign to variable teacher
var teacher = new Person("Mr M", "3.0/3.0", "Teacher");  // object type is easy to work with in JavaScript

// define a student Array of Person(s)
var students = [ 
    new Person("Nicolas", "2.7/3.0", "Scrum Master"),
    new Person("Andrew", "2.7+/3.0", "Backend Dev"),
    new Person("Bailey", "2.7+/3.0", "Backend Dev"),
    new Person("Rohan", "2.7/3.0", "Frontend Dev"),
];

// define a classroom and build Classroom objects and json
function Classroom(teacher, students){ // 1 teacher, many student
    this.teacher = teacher;
    this.classroom = [teacher];
    // add each Student to Classroom
    this.students = students;
    this.students.forEach(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
teamScore = new Classroom(teacher, students);

// 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: 1px solid coral;" +
      "box-shadow: 1em 0.6em 0.6em skyblue;"
    );
  
    // 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>" + "Peer Grade" + "</mark></th>";
    body += "<th><mark>" + "Role" + "</mark></th>";
    body += "</tr>";
    // Data of Array, iterate through each row of teamScore.classroom 
    for (var row in teamScore.classroom) {
      // tr for each row, a new line
      body += "<tr>";
      // td for each column of data
      body += "<td>" + teamScore.classroom[row].name + "</td>";
      body += "<td>" + teamScore.classroom[row].peergrade + "</td>";
      body += "<td>" + teamScore.classroom[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(teamScore._toHtml());
Nicolas' JavaScript practice
</table></div> </div> </div> </div> </div> </div> </div>
Name Peer Grade Role
Mr M 3.0/3.0 Teacher
Nicolas 2.7/3.0 Scrum Master
Andrew 2.7+/3.0 Backend Dev
Bailey 2.7+/3.0 Backend Dev
Rohan 2.7/3.0 Frontend Dev