JavaScript
console.log("Hello World!");
var speak = "Hello World";
console.log(speak);
function logIt(output) {
console.log(output);
}
logIt(speak);
console.log("Welcome!")
logIt("Hello Students!");
logIt(2022)
// define a function to hold data for a Person
function Person(name, ghID, classOf) {
this.name = name;
this.ghID = ghID;
this.classOf = classOf;
this.role = "Scrum Master";
}
// define a setter for role in Person data
Person.prototype.setRole = function(role) {
this.role = role;
}
// define a JSON conversion "method" associated with Person
Person.prototype.toJSON = function() {
const obj = {name: this.name, ghID: this.ghID, classOf: this.classOf, 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 scrummaster = new Person("Jazair Tallman", "@jz21324", 2024); // object type is easy to work with in JavaScript
logIt(scrummaster); // before role
logIt(scrummaster.toJSON()); // ok to do this even though role is not yet defined
// output of Object and JSON/string associated with Teacher
scrummaster.setRole("Scrum Master"); // set the role
logIt(scrummaster);
logIt(scrummaster.toJSON());