You may want to check out my full lesson on JavaScript objects, constructors and arrays.
Mouse Hover over the ➼ blue text in the description to highlight the code.
// Card Constructor
function Card (name,img,skillArray,alignment){
this.name = name;
this.img = "cards/" + img;
this.skillArray = skillArray;
this.alignment = alignment;
}
➼ Card Object -
This constructor defines an object named "Card". Constructor functions normally begin
with a capital letter.
➼ Parameters -
name, img, skillArray, and alignment are the parameters tat we are passing into
the Card function.
➼ name -
The name of the card
➼ img - The name of the image file associated with the card.
➼ skillArray - An index array of skill points.
➼ alignment - Lawful (0) or Unlawful (1)
Once a class's skill array is defined we can declare a specific character. Let's start with Paladin Hatnix.
// Paladin Skill Array
var paladinSkills = [20,5,15,18,5,10];
➼ Intelligence
➼ Strength
➼ Dexterity
➼ Spirituality
➼ Brutality
➼ Diplomacy
**Note: Each skill has a value 1-20 (like 20 sided dice)
// Declare Paladin Hatnix
var hatnix = new Card ("Paladin Hatnix", "paladin-hatnix.png", paladinSkills, 0);
➼ Character's Name
➼ File name of associated image
➼ Paladin Skill Array
➼ Alignment (lawful)