Javascript Tutorial
This is the Javascript tutorial assignment. I will be testing different things in Javascript and playing around with the code.
function ID(name, sport, APs) {
this.name = name;
this.sport = sport;
this.APs = APs;
}
// define a setter for role in Person data
ID.prototype.setRole = function(role) {
this.role = role;
}
// define a JSON conversion "method" associated with Person
ID.prototype.toJSON = function() {
const obj = {name: this.name, sport: this.sport, APs: this.APs, role: this.role};
const json = JSON.stringify(obj);
return json;
}
function logItType(output){
console.log(output);
}
// make a new Person and assign to variable teacher
var table1 = new ID("Alan", "swim", 4); // object type is easy to work with in JavaScript
logItType(table1); // before role
logItType(table1.toJSON()); // ok to do this even though role is not yet defined
// output of Object and JSON/string associated with Teacher
table1.setRole("Main User"); // set the role
logItType(table1);
logItType(table1.toJSON());
var tableGroup = [
new ID("Ederick", "swim", "unknown"),
new ID("Noor", "MMA", "unknown"),
new ID("Steven", "unknown", "unknown")
]
logItType(tableGroup);
logItType(table1)