JavaScript Proof
This is a demonstration of how I used JavaScript's to create the table for the group behind Udderly Delectable
My Understanding of JavaScript (based on the program)
- JavaScript does support OOP (Object-Oriented Programming), but classes are in the form of functions
- Python has "print("Hello, World!")," while JavaScript has "console.log("Hello, World!")."
- The OOP features in JavaScript that were demonstrated in the program were initialization, constructor methods, and instantiation. These are all under the OOP concept of Encapsulation.
- HTML integration using the "._toHTML()" method was used.
function logItType(output) {
console.log(typeof output, ";", output);
}
function TeamMember(name, ghID, classOf) {
this.name = name;
this.ghID = ghID;
this.classOf = classOf;
this.role = "";
}
TeamMember.prototype.setRole = function(role) {
this.role = role;
}
TeamMember.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 scrumZaddae = new TeamMember("Samarth", "Samarth Kalanke", 2025);
scrumZaddae.setRole("Teacher");
var teamMembers = [
new TeamMember("Paaras", "PaarasPurohit", 2025),
new TeamMember("Haoxuan", "JasoXDDD", 2024),
new TeamMember("AJ", "KKcbal", 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()));
}
agileTeam = new Classroom(scrumZaddae, teamMembers);
Classroom.prototype._toHtml = function() {
var style = (
"display:inline-block;" +
"background:black;" +
"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 agileTeam.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>"
);
};
// IJavaScript HTML processor receive parameter of defined HTML fragment
$$.html(agileTeam._toHtml());