Learning Arrays and Objects with Voltron Characters
I am confused about negative checking in Javascript. Fixing this.
by db_dev
HTML
<dl id="paladins"></dl>
<dl id="lions"></dl>
SCSS
body {
font-family: "Open Sans";
font-size: 11px;
}
// Definition List
dl {
dt {
font-weight: bold;
}
dd {
margin-left: 12px;
}
}
JavaScript
paladins = ["Shiro", "Keith", "Lance", "Hunk", "Pidge"]
$("<dt>Paladins of Voltron</dt>").appendTo("#paladins");
$.each(paladins, function(i, v) {
$("<dd>" + v + "</dd>").appendTo("#paladins");
});
//---------------------------------------------------------
// Check to see if any member is Altean
function teamMember(name, race, role) {
this.name = name;
this.race = race;
this.role = role;
}
var allura = new teamMember("Princess Allura", "Altean", "Leader");
var coran = new teamMember("Coran Hieronymus Wimbleton Smythe", "Altean", "Advisor");
var shiro = new teamMember("Shiro", "Human", "Pilot");
var keith = new teamMember("Keith", "Human", "Pilot");
var lance = new teamMember("Lance", "Human", "Pilot");
var hunk = new teamMember("Hunk", "Human", "Pilot");
var pidge = new teamMember("Pidge", "Human", "Pilot");
var kolivan = new teamMember("Kolivan", "Galra", "Leader");
function voltronLion(color, weapon, pilot) {
this.color = color;
this.weapon = weapon;
this.pilot = pilot;
}
var blackLion = new voltronLion("Black", "Sword", shiro);
var redLion = new voltronLion("Red", "Sword", keith);
var greenLion = new voltronLion("Green", "Grapple", pidge);
var blueLion = new voltronLion("Blue", "Energy Chain", lance);
var yellowLion = new voltronLion("Yellow", "Cannon", hunk);
var lions = [];
lions.push({
blackLion,
redLion,
blueLion,
greenLion,
yellowLion
});
$.each(lions, function(i, v) {
$.each(lions[i], function(k, v) {
var phrase = v.pilot.name + "(" + v.pilot.race + "), " + v.weapon;
var title = "<dt>" + v.color + " Lion </dt>"
$(title).appendTo("#lions");
$("<dd>" + phrase + "</dd>").appendTo("#lions");
})
});
//----------------------------------------------------------------
function galraSoldier(name, rank, loyalTo) {
this.name = name;
this.rank = rank;
this.loyalTo = loyalTo;
}
var prorock = new galraSoldier("Prorock", "Commander", "Zarkon");
var throk = new...