Javascript Moment
Wooooo, yeah baby, thats what we've been waiting for, thats what its all about, wooooo
function game(name, genre, year, players) {
this.name = name;
this.genre = genre;
this.year = year;
this.players = players;
this.role = "";
}
game.prototype.setRole = function(role) {
this.role = role;
}
game.prototype.toJSON = function() {
const obj = {name: this.name, genre: this.genre, year: this.year, players: this.players, role: this.role};
const json = JSON.stringify(obj);
return json;
}
var movies = new game("Uncharted", "Action", "2022", "n/a");
logItType(movies);
logItType(movies.toJSON());
movies.setRole("Movie");
logItType(movies);
logItType(movies.toJSON());
var games = [
new game("Minecraft", "Sandbox", "2011", "141 Million"),
new game("R6S", "FPS", "2015", "70 Million"),
new game("Fortnite", "3rd Person BR", "2017", "270 Million"),
new game("Apex", "1st Person BR", "2019", "~100 Million"),
new game("Roblox", "Sandbox", "2006", "230 Million"),
new game("Pokemon Go", "Augmented Reality", "2016", "632 Million"),
new game("Halo Infinite", "FPS", "2021", "20 Million"),
new game("Terraria", "Sandbox", "2011", "~66 Million"),
]
function Theatre(movies, games){
movies.setRole("Movie");
this.movies = movies;
this.theatre = [movies];
this.games = games;
this.games.forEach(game => { game.setRole("Game"); this.theatre.push(game); });
this.json = [];
this.theatre.forEach(game => this.json.push(game.toJSON()));
}
compsci = new Theatre(movies, games);
logItType(compsci.theatre);
logItType(compsci.theatre[0].name);
logItType(compsci.json[0]);
logItType(JSON.parse(compsci.json[0]));
Classroom.prototype._toHtml = function() {
var style = (
"display:inline-block;" +
"border: 2px solid grey;"
);
var body = "";
body += "<tr>";
body += "<th><mark>" + "Name" + "</mark></th>";
body += "<th><mark>" + "Genre" + "</mark></th>";
body += "<th><mark>" + "Year" + "</mark></th>";
body += "<th><mark>" + "Players" + "</mark></th>";
body += "</tr>";
for (var row of compsci.classroom) {
body += "<tr>";
body += "<td>" + row.name + "</td>";
body += "<td>" + row.genre + "</td>";
body += "<td>" + row.year + "</td>";
body += "<td>" + row.players + "</td>";
body += "<tr>";
}
return (
"<div style='" + style + "'>" +
"<table>" +
body +
"</table>" +
"</div>"
);
};
$$.html(compsci._toHtml());