21 September Notes
We're doing stuff with javascript today. the apcsp repository in vscode glitched out and I can't sync it. I can't reclone it because it says that apcsp already exists. the javascript stuff didnt work although i checked through powershell and it said I had it installed. tests shall comence
var msg = "hello";
console.log(msg);
The kernel is not working. I can not find any errors through powershell. Maybe vscode is just glitching out at the moment. I installed extensions through vscode for javascript
function logIt(output) {
console.log(output)
}
logIt(msg)
function is used to define a function. logit is the name for the function. output can be used as a variable for what's placed inside the parenthesis when executing the function.
function logItType(output) {
console.log(typeof output, ";", output)
}
logit("hello")
logit(2022)
logit([1, 2, 3])
function Person(name, hp, atk) {
this.Name = name;
this.HP = hp;
this.ATK = atk;
this.Role = "";
}
Person.prototype.setRole = function(role) {
this.Role = role;
}
Person.prototype.toJSON = function() {
const obj = {name: this.Name, hp: this.HP, atk: this.ATK, role: this.Role};
const json = JSON.stringify(obj);
return json;
}
var sword = new Person("joe", 2, 3);
logItType(sword);
logItType(sword.toJSON());
sword.setRole("Swordsman");
logItType(sword)
logItType(sword.toJSON())
var army = [
new Person("Nate", 10, 10),
new Person("Igor", 13, 14),
new Person("Greg", 4, 3),
new Person("Gilligan", 25, 27),
new Person("Elliot", 9, 11),
new Person("Rob", 12, 10)
];
function Military(sword, army) {
sword.setRole("Swordsman");
this.Sword = sword;
this.Military = [sword];
this.army = army;
this.army.forEach(army => { army.setRole("Soldier"); this.Military.push(army); });
this.json = [];
this.Military.forEach(person => this.json.push(person.toJSON()));
}
sec9 = new Military(sword, army)
logItType(sec9.Military);
logItType(sec9.Military[0].Name);
a conversion to JSON is needed for the js code to be displayed through ._toHtml
Military.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>" + "HP" + "</mark></th>";
body += "<th><mark>" + "ATK" + "</mark></th>";
body += "<th><mark>" + "Role" + "</mark></th>";
body += "</tr>";
for (var row of sec9.Military) {
body += "<tr>";
body += "<td>" + row.Name + "</td>";
body += "<td>" + row.HP + "</td>";
body += "<td>" + row.ATK + "</td>";
body += "<td>" + row.Role + "</td>";
body += "<tr>";
}
return (
"<div style='" + style + "'>" +
"<table>" +
body +
"</table>" +
"</div>"
);
};
$$.html(sec9._toHtml());