function type(output){
console.log(output);
}
function Chess(name, rank, yrsplay){
this.name = name;
this.rank = rank;
this.yrsplay = yrsplay;
this.exp = ""
}
Chess.prototype.setExp = function(exp){
this.exp = exp;
}
Chess.prototype.toJSON = function(){
const obj = {name: this.name, rank: this.rank, yrsplay: this.yrsplay, exp: this.exp};
const json = JSON.stringify(obj);
return json;
}
var chess_players = [
new Chess("Magnus Carlsen",2856, 26),
new Chess("Ding Liren",2811,13),
new Chess("Ian Nepomniachtchi",2793,28),
];
function Leaderboard(chess_play){
chess_play.setExp("Grandmaster");
this.chess_play = chess_play;
this.Leaderboard = [chess_play];
this.json = [];
this.classroom.forEach(Chess => this.json.push(Chess.toJSON()));
}
leaders = new Leaderboard(chess_players)
Chess.prototype._toHtml = function() {
var style = (
"display:inline-block;" +
"border: 2px solid grey;" +
"box-shadow: 0.8em 0.4em 0.4em grey;"
);
var body = "";
body += "<tr>";
body += "<th><mark>" + "Name" + "</mark></th>";
body += "<th><mark>" + "Rank" + "</mark></th>";
body += "<th><mark>" + "Years Played" + "</mark></th>";
body += "<th><mark>" + "Experience" + "</mark></th>";
body += "</tr>";
for (var row of leaders.classroom) {
body += "<tr>";
body += "<td>" + row.name + "</td>";
body += "<td>" + row.rank + "</td>";
body += "<td>" + row.yrsplay + "</td>";
body += "<td>" + row.exp + "</td>";
body += "<tr>";
}
return (
"<div style='" + style + "'>" +
"<table>" +
body +
"</table>" +
"</div>"
);
};
$$.html(leaders._toHtml());