JavaScript Tutorial
console.log("Hello, World!");
console.log("testing out java console.log")
console.log("trial")
var msg = "Hello, World!";
console.log(msg);
function logIt(output) {
console.log(output);
}
logIt(msg);
console.log("Reuse of logIT")
logIt("Hello, Mr Yeung Please Give Me a 3!");
logIt(100)
logIt("percent!")
function logItType(output) {
console.log(typeof output, ";", output);
}
console.log("Testing Out JavaScript Functions")
logItType(" A string");
logItType(2020);
logItType([1, 2, 3]);
function Person(player, team, region) {
this.player = player;
this.team = team;
this.region = region;
this.role = "";
}
Person.prototype.setRole = function(role) {
this.role = role;
}
Person.prototype.toJSON = function() {
const obj = {player: this.player, team: this.team, region: this.region, role: this.role};
const json = JSON.stringify(obj);
return json;
}
var Player = new Person("Krishiv", " Del Mar Sharks","USA" );
Player.setRole("Player");
logItType(Player);
logItType(Player.toJSON());
var gamers = [
new Person("Messi", "PSG", "europe"),
new Person("Ronaldo", "ManU", "europe"),
new Person("vela", "LAFC", "USA"),
new Person("mount", "CHELSEA FC", "europe"),
];
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()));
}
compsci = new Classroom(teacher, students);
logItType(compsci.classroom);
logItType(compsci.classroom[0].name);
logItType(compsci.json[0]);
Classroom.prototype._toHtml = function() {
var style = (
"display:inline-block;" +
"background:green;" +
"border: 2px solid grey;" +
"box-shadow: 0.8em 0.4em 0.4em grey;"
);
var body = "";
body += "<tr>";
body += "<th><mark>" + "Player" + "</mark></th>";
body += "<th><mark>" + "Team" + "</mark></th>";
body += "<th><mark>" + "Region" + "</mark></th>";
body += "</tr>";
for (var row of compsci.classroom) {
body += "<tr>";
body += "<td>" + row.player + "</td>";
body += "<td>" + row.team + "</td>";
body += "<td>" + row.region + "</td>";
body += "<tr>";
}
return (
"<div style='" + style + "'>" +
"<table>" +
body +
"</table>" +
"</div>"
);
};
$$.html(compsci._toHtml());