Javascript Use
Javascript
var mep = "derpin around";
console.log(mep)
function logItType(output) { //putting logItType as an example of a function
console.log(typeof output, ";", output);
}
p = 1;
//attempted to use dates, failed
// define a function to hold data for a Person
function Mess(size, disgust, madeBy) {
this.size = size;
this.disgust = disgust;
this.madeBy = madeBy;
this.role = "";
}
// define a setter for role in Person data
Mess.prototype.setRole = function(role) {
this.role = role;
}
// define a JSON conversion "method" associated with Person
Mess.prototype.toJSON = function() {
const obj = {Size: this.size, disgust: this.disgust, madeBy: this.madeBy, role: this.role};
const json = JSON.stringify(obj);
return json;
}
// make a new Person and assign to variable teacher
var teacger = new Mess("5", "7", "Lad");
teacger.setRole("disturb");
// output of Object and JSON/string associated with Teacher
logItType(teacger); // object type is easy to work with in JavaScript
logItType(teacger.toJSON()); // json/string is useful when passing data on internet
// define an Array of messes made
var minor = [
new Mess("8", "3", "Ann"),
new Mess("2", "4", "Pal"),
new Mess("6", "5", "Sal"),
new Mess("1", "0", "Mia"),
new Mess("10", "9", "Rad"),
new Mess("3", "4", "Telu")
];
// define a group of people and build group objects and json
function Group(teacher, minor){ // 1 teacher, many student
// start Classroom with Teacher
teacger.setRole("disturb");
this.teacger = teacher;
this.Group = [teacher];
// add each Student to Classroom
this.minor = minor;
this.minor.forEach(minor => { minor.setRole("Minin"); this.Group.push(minor); });
// build json/string format of Classroom
this.json = [];
this.Group.forEach(mess => this.json.push(mess.toJSON()));
}
// make a CompSci classroom from formerly defined teacher and students
LatterPeople = new Group(teacger, minor);
// output of Objects and JSON in CompSci classroom
logItType(LatterPeople.Group); // constructed classroom object
logItType(LatterPeople.Group[0].name); // abstract 1st objects name
logItType(LatterPeople.json[0]); // show json conversion of 1st object to string
logItType(JSON.parse(LatterPeople.json[0])); // show JSON.parse inverse of JSON.stringify