My Infinite Loop is Finite


#1

I was sandboxing around with JavaScript objects and accidentally caused an infinite loop. Except, I didn't. I tested my code multiple times and... well see for yourself:

var roster = {
    Liv: {
        name:     "Olivia Rooney",
        rank:     "Her Majesty, The Queen [♛]",
        gender:   "Female",
        nickName: "Liv",
        age:      20
    },
    Maddie: {
        name:     "Maddie Rooney",
        rank:     "Her Majesty, The Queen [♛]",
        gender:   "Female",
        nickName: "Mad-Dog",
        age:      20
    },
    Emma: {
        name:     "Emma Ross",
        rank:     "Her Majesty, The Princess [♛]",
        gender:   "Female",
        nickName: "The Crimson Samurai",
        age:      19
    },
    Aqua: {
        name:     "Aqua McCoolah",
        rank:     "General [★★★★★]",
        gender:   "Male",
        nickName: "Aqua Phoenix",
        age:      21
    },
    Mikayla: {
        name:     "Mikayla McCoolah",
        rank:     "General [★★★★]",
        gender:   "Stabbitha",
        age:      27
    },
    Lynx: {
        name:     "Lynx McCoolah",
        rank:     "General [★★★]",
        gender:   "Female",
        nickName: "Master of Stealth",
        age:      21
    },
    Jack: {
        name:     "Jack McCoolah",
        rank:     "General [★★★]",
        gender:   "Male",
        nickName: "The Rogue Shadow/The Defender",
        age:      20
    },
    Scarlett: {
        name:     "Scarlett McCoolah",
        rank:     "General [★★]",
        gender:   "Female",
        nickName: "Scar",
        age:      18
    },
    Nile: {
        name:     "Nile McCoolah",
        rank:     "General [★★]",
        gender:   "Male",
        nickName: "Master of Water",
        age:      19
    },
    Chase: {
        name:     "Chase Davenport",
        rank:     "General [★★]",
        gender:   "Male",
        nickName: "Master of Intelligence",
        age:      18
    },
    Bree: {
        name:     "Bree Davenport",
        rank:     "General [★]",
        gender:   "Female",
        nickName: "Master of Speed",
        age:      19
    },
    Adam: {
        name:     "Adam Davenport",
        rank:     "General [★]",
        gender:   "Male",
        nickName: "Master of Strength",
        age:      23
    },
    Leo: {
        name:     "Leo Dulley",
        rank:     "General [★]",
        gender:   "Male",
        nickName: "Metal Limbs",
        age:      17
    },
    Skylar: {
        name:     "Skylar McCoolah",
        rank:     "General [★]",
        gender:   "Female",
        nickName: "Sky Mage",
        age:      16
    },
    SkylarStorm: {
        name:     "Skylar Storm",
        rank:     "Colonel",
        gender:   "Female",
        nickName: "Ms. Storm",
        age:      18
    },
    Winter: {
        name:     "Winter McCoolah",
        rank:     "Colonel",
        gender:   "Female",
        nickName: "Timebreaker",
        age:      15
    },
    Connor: {
        name:     "Connor McCoolah",
        rank:     "Colonel",
        gender:   "Male",
        nickName: "Mr. Invulnerable",
        age:      15
    },
    Amber: {
        name:     "Amber McCoolah",
        rank:     "Lieutenant Colonel",
        gender:   "Female",
        nickName: "The Berserker",
        age:      14
    },
    Kim: {
        name:     "Kim Krawford",
        rank:     "Lieutenant Colonel",
        gender:   "Female",
        nickName: "Agent Krawford",
        age:      20
    },
    Douglas: {
        name:     "Douglas Davenport",
        rank:     "Lieutenant Colonel",
        gender:   "Male",
        nickName: "N/A",
        age:      42
    },
    Donald: {
        name:     "Donald Davenport",
        rank:     "Lieutenant Colonel",
        gender:   "Male",
        nickName: "Big-D",
        age:      44
    },
    Mahooma: {
        name:     "Michael Mahooma",
        rank:     "Major",
        gender:   "Male",
        nickName: "Mahooma",
        age:      38
    },
    Mason: {
        name:     "Mason McCoolah",
        rank:     "Major",
        gender:   "Male",
        nickName: "The Sasquatch",
        age:      40
    },
    Jason: {
        name:     "Jason McCoolah",
        rank:     "Major",
        gender:   "Male",
        nickName: "Mr. Reckless",
        age:      36
    },
    Parker: {
        name:     "Parker Rooney",
        rank:     "Captain",
        gender:   "Male",
        nickName: "Doctor P",
        age:      16
    },
    Ruby: {
        name:     "Ruby Rooney",
        rank:     "Captain",
        gender:   "Female",
        nickName: "The Red Ribbon",
        age:      14
    },
    Joey: {
        name:     "Joseph Rooney",
        rank:     "Captain",
        gender:   "Male",
        nickName: "Falcon",
        age:      18
    },
    Thompson: {
        name:     "Ash Thompson",
        rank:     "Captain",
        gender:   "Male",
        nickName: "Mercenary",
        age:      32
    }
};
var rosterList = [
    roster.Liv, 
    roster.Maddie, 
    roster.Emma, 
    roster.Aqua, 
    roster.Lynx,
    roster.Mikayla, 
    roster.Jack, 
    roster.Scarlett, 
    roster.Nile, 
    roster.Chase,
    roster.Bree,
    roster.Adam,
    roster.Leo,
    roster.Sky,
    roster.SkylarStorm,
    roster.Winter,
    roster.Connor,
    roster.Amber,
    roster.Kim,
    roster.Douglas,
    roster.Donald,
    roster.Mahooma,
    roster.Mason,
    roster.Jason,
    roster.Parker,
    roster.Ruby,
    roster.Joey
];
var teams = {
    EliteForce: {
        TeamName: "         ~ Elite Force ~       ",
        TeamLeader: roster.Chase, 
        SecondInCommand: roster.SkylarStorm,
        TeamMembers: [roster.Bree, roster.Adam, roster.Leo],
        Handlers: [roster.Douglas, roster.Donald]
    },
    TheOGTeam: {
        TeamName: "       ~ The Original Team ~       ",
        TeamLeader: roster.Aqua,
        SecondInCommand: roster.Mikayla,
        TeamMembers: [roster.Jack, roster.Lynx],
        Handlers: [roster.Mason, roster.Jason, roster.Mahooma]
    },
    TheNewTeam: {
        TeamName: "         ~ The Team ~       ",
        TeamLeader: roster.Aqua,
        SecondInCommand: roster.Mikayla,
        TeamMembers: [
            roster.Jack,
            roster.Lynx,
            roster.Nile,
            roster.Scarlett,
            roster.Skylar,
            roster.Amber,
            roster.Winter,
            roster.Connor
        ],
        Handlers: [roster.Mason, roster.Jason, roster.Mahooma]
    },
    TheRoyalDefenders: {
        TeamName: "      ~ The Royal Defenders ~     ",
        TeamLeader: roster.Jack,
        SecondInCommand: roster.Skylar,
        TeamMembers: [roster.Winter, roster.Connor],
        Handlers: [roster.Kim, roster.Thompson]
    }
};
var teamsList = [
    teams.EliteForce,
    teams.TheOGTeam,
    teams.TheNewTeam,
    teams.TheRoyalDefenders
];

var logObject = function(object) {
    console.log("Name:     " + object.name);
    console.log("Gender:   " + object.gender);
    console.log("Age:      " + object.age);
    console.log("Rank:     " + object.rank);
    console.log("Nickname: " + object.nickName);
};

var logName = function(object) {
    return object.name;
};

var logRoster = function() {
    for (i = 0; i < rosterList.length; i++) {
        logObject(rosterList[i]);
        console.log("");
    };
};

var logTeam = function(team) {
    console.log(team.TeamName);
    console.log("Team Leader:       " + logName(team.TeamLeader));
    console.log("Second in Command: " + logName(team.SecondInCommand));
    console.log("Team Members:      " + logName(team.TeamMembers[0]));
    for (i = 1; i < team.TeamMembers.length; i++) {
        console.log("                   " + logName(team.TeamMembers[i]));
    };
    console.log("Handlers:          " + logName(team.Handlers[0]));
    for (i = 1; i < team.Handlers.length; i++) {
        console.log("                   " + logName(team.Handlers[i]));
    };
};

var logTeams = function() {
    for (i = 0; i < teamsList.length; i++) {
        logTeam(teamsList[i]);
        console.log("");
        console.log("");
    };
};

logTeams();

This code doesn't work and crashes my page. However, if I manually call the code that would run when I call:

logTeams();

Like so:

logTeam(teamsList[0]);
console.log("");
console.log("");
logTeam(teamsList[1]);
console.log("");
console.log("");
logTeam(teamsList[2]);
console.log("");
console.log("");
logTeam(teamsList[3]);
console.log("");
console.log("");

It works. I guess my question is why does calling that function result in an infinite loop/page crash, but manually calling the code that would run if you called the function works how it should?


#2

Can be created in one statement:

rosterList = Object.keys(roster)

Same here,

teamsList = Object.keys(teams)

I usually cringe when there are reams of console.log() statments. Not only is it incredibly slow, it makes reading a real chore. The cure for this is to generate a string that inserts newline characters after each line, but concatenates everything into a single object. Then log the object.

As for key names, it is common to see keynames that are lowercase or camelCase. Beginning names with a capital just adds to confusion.

Data should not be stored with white space or special characters. Format the output when you go to log it, and keep your data as plain as possible.

As for the infinite loop, I still haven't run your code and would rather wait until after you reduce it a bit, according to the above suggestions.


#3

Alright, I did most of what you asked for, but I still don't get how to do this:

Here is my updated code just so you know exactly what I did:

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "Master of Stealth",
        age: 21
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Water",
        age: 19
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky Mage",
        age: 16
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32
    }
};
var rosterList = Object.keys(roster);
var teams = {
    eliteForce: {
        teamName: "Elite Force",
        teamLeader: roster.chase,
        secondInCommand: roster.skylarStorm,
        teamMembers: [roster.bree, roster.adam, roster.leo],
        handlers: [roster.douglas, roster.donald]
    },
    theOGTeam: {
        teamName: "The Original Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [roster.jack, roster.lynx],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theNewTeam: {
        teamName: "The Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [
            roster.jack,
            roster.lynx,
            roster.nile,
            roster.scarlett,
            roster.skylar,
            roster.amber,
            roster.winter,
            roster.connor
        ],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theRoyalDefenders: {
        teamName: "The Royal Defenders",
        teamLeader: roster.jack,
        secondInCommand: roster.skylar,
        teamMembers: [roster.winter, roster.connor],
        handlers: [roster.kim, roster.thompson]
    }
};
var teamsList = Object.keys(teams);

var logObject = function(object) {
    console.log("Name: " + object.name);
    console.log("Gender: " + object.gender);
    console.log("Age: " + object.age);
    console.log("Rank: " + object.rank);
    console.log("Nickname: " + object.nickName);
};

var logName = function(object) {
    return object.name;
};

var logRoster = function() {
    for (i = 0; i < rosterList.length; i++) {
        logObject(rosterList[i]);
        console.log("");
    };
};

var logTeam = function(team) {
    console.log(team.teamName);
    console.log("Team Leader: " + logName(team.teamLeader));
    console.log("Second in Command: " + logName(team.secondInCommand));
    console.log("Team Members: " + logName(team.teamMembers[0]));
    for (i = 1; i < team.teamMembers.length; i++) {
        console.log(logName(team.teamMembers[i]));
    };
    console.log("Handlers: " + logName(team.handlers[0]));
    for (i = 1; i < team.handlers.length; i++) {
        console.log(logName(team.handlers[i]));
    };
};

var logTeams = function() {
    for (i = 0; i < teamsList.length; i++) {
        logTeam(teamsList[i]);
        console.log("");
        console.log("");
    };
};

logTeams();

#4

If a loop isn't iterating the way it should, observe what controls it

If you can't see it, show it

If other output makes it difficult to see what you want, filter the output or in some other way disable it.


#5

I'm still not getting it... Here is version 1 of my updated code:

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "Master of Stealth",
        age: 21
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Water",
        age: 19
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky Mage",
        age: 16
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32
    }
};
var teams = {
    eliteForce: {
        teamName: "Elite Force",
        teamLeader: roster.chase,
        secondInCommand: roster.skylarStorm,
        teamMembers: [roster.bree, roster.adam, roster.leo],
        handlers: [roster.douglas, roster.donald]
    },
    theOGTeam: {
        teamName: "The Original Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [roster.jack, roster.lynx],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theNewTeam: {
        teamName: "The Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [
            roster.jack,
            roster.lynx,
            roster.nile,
            roster.scarlett,
            roster.skylar,
            roster.amber,
            roster.winter,
            roster.connor
        ],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theRoyalDefenders: {
        teamName: "The Royal Defenders",
        teamLeader: roster.jack,
        secondInCommand: roster.skylar,
        teamMembers: [roster.winter, roster.connor],
        handlers: [roster.kim, roster.thompson]
    }
};
var teamsList = Object.keys(teams);

var logName = function(object) {
    return object.name;
};
var logTeams = function(team) {
    for (j = 0; j < team.length; j++) {
        var teams = team[j]
        console.log(teams.teamName);
        console.log("Team Leader: " + logName(teams.teamLeader));
        console.log("Second in Command: " + logName(teams.secondInCommand));
        for (i = 0; i < teams.teamMembers.length; i++) {
            console.log("Team Member: " + logName(team.teamMembers[i]));
        };
        for (i = 0; i < teams.handlers.length; i++) {
            console.log("Handler: " + logName(teams.handlers[i]));
        };
    };
};

logTeams(teamsList);

This is what appears in the console when I call the above code:

undefined
TypeError: Cannot read property 'name' of undefined

Here is version 2 of my updated code:

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "Master of Stealth",
        age: 21
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Water",
        age: 19
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky Mage",
        age: 16
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32
    }
};
var teams = {
    eliteForce: {
        teamName: "Elite Force",
        teamLeader: roster.chase,
        secondInCommand: roster.skylarStorm,
        teamMembers: [roster.bree, roster.adam, roster.leo],
        handlers: [roster.douglas, roster.donald]
    },
    theOGTeam: {
        teamName: "The Original Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [roster.jack, roster.lynx],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theNewTeam: {
        teamName: "The Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [
            roster.jack,
            roster.lynx,
            roster.nile,
            roster.scarlett,
            roster.skylar,
            roster.amber,
            roster.winter,
            roster.connor
        ],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theRoyalDefenders: {
        teamName: "The Royal Defenders",
        teamLeader: roster.jack,
        secondInCommand: roster.skylar,
        teamMembers: [roster.winter, roster.connor],
        handlers: [roster.kim, roster.thompson]
    }
};
var teamsList = Object.keys(teams);

var logName = function(object) {
    return object.name;
};

var logTeam = function(team) {
    console.log(team.teamName);
    console.log("Team Leader: " + logName(team.teamLeader));
    console.log("Second in Command: " + logName(team.secondInCommand));
    for (i = 0; i < team.teamMembers.length; i++) {
        console.log("Team Member: " + logName(team.teamMembers[i]));
    };
    for (i = 0; i < team.handlers.length; i++) {
        console.log("Handler: " + logName(team.handlers[i]));
    };
};

var logTeams = function() {
    for (i = 0; i < teamsList.length; i++) {
        logTeams(teamsList[i]);
    };
};

logTeams();

This is what appears in the console if I call THAT code:

RangeError: Maximum call stack size exceeded

I guess what I'm saying is does anybody have any Ideas what I'm doing wrong here?

Also, I did find one way to get it to work, (It's kind of stupid), but here it is in as condensed a form as I could get it:

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "Master of Stealth",
        age: 21
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Water",
        age: 19
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky Mage",
        age: 16
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32
    }
};
var teams = {
    eliteForce: {
        teamName: "Elite Force",
        teamLeader: roster.chase,
        secondInCommand: roster.skylarStorm,
        teamMembers: [roster.bree, roster.adam, roster.leo],
        handlers: [roster.douglas, roster.donald]
    },
    theOGTeam: {
        teamName: "The Original Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [roster.jack, roster.lynx],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theNewTeam: {
        teamName: "The Team",
        teamLeader: roster.aqua,
        secondInCommand: roster.mikayla,
        teamMembers: [
            roster.jack,
            roster.lynx,
            roster.nile,
            roster.scarlett,
            roster.skylar,
            roster.amber,
            roster.winter,
            roster.connor
        ],
        handlers: [roster.mason, roster.jason, roster.mahooma]
    },
    theRoyalDefenders: {
        teamName: "The Royal Defenders",
        teamLeader: roster.jack,
        secondInCommand: roster.skylar,
        teamMembers: [roster.winter, roster.connor],
        handlers: [roster.kim, roster.thompson]
    }
};
var logName = function(object) {
    return object.name;
};
var newLine = function(lines) {
    for (i = 0; i < lines; i++) {
        console.log();
    };
};
var logTeam = function(team) {
    console.log(team.teamName);
    console.log("Team Leader: " + logName(team.teamLeader));
    console.log("Second in Command: " + logName(team.secondInCommand));
    for (i = 0; i < team.teamMembers.length; i++) {
        console.log("Team Member: " + logName(team.teamMembers[i]));
    };
    for (i = 0; i < team.handlers.length; i++) {
        console.log("Handler: " + logName(team.handlers[i]));
    }; 
};
logTeam(teams.eliteForce); newLine(2);
logTeam(teams.theOGTeam); newLine(2);
logTeam(teams.theNewTeam); newLine(2);
logTeam(teams.theRoyalDefenders);

#6

The variable controlling your loop is i, so watch how i changes while you run the loop


#7

There is your recursion. Did you mean to write,

    logTeam(teamsList[i]);

I'm wondering if it wouldn't be simpler to put all the data in one place.

Eg.

    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18,
        team: "Elite Force"
        leader: true,
        second: false,
        handler: false
    },

#8

Oh my god, I'm blind...

Also...

You're a genius.


#9

Alright, here is my updated code:

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20,
        teamOne: "none",
        teamOnelLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "The Archer",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: true,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "The Admiral",
        age: 19,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky",
        age: 16,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: true,
        teamTwoHandler: false
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    }
};
var rosterList = Object.keys(roster);

var newLine = function(lines) {
    for (i = 0; i < lines; i++) {
        console.log();
    };
};

var logName = function(object) {
    return object.name;
};

var logTeamTwo = function(object) {
    if (object.teamTwo != "none") {
        if (object.teamTwoLeader == true) {
            console.log("Leader of " + object.teamTwo);
        } else if (object.teamTwoSecond == true) {
            console.log("Second-in-command of " + object.teamTwo);
        } else if (object.teamTwoHandler == true) {
            console.log("Handler of " + object.teamTwo);
        } else {
            console.log("Member of " + object.teamTwo);
        };
    };
};

var logObject = function(object) {
    console.log("Name: " + object.name);
    console.log("Gender: " + object.gender);
    console.log("Age: " + object.age);
    console.log("Rank: " + object.rank);
    console.log("Nickname: " + object.nickName);
    if (object.teamOne != "none") {
        if (object.teamOneLeader == true) {
            console.log("Leader of " + object.teamOne);
            logTeamTwo(object);
        } else if (object.teamOneSecond == true) {
            console.log("Second-in-command of " + object.teamOne);
            logTeamTwo(object);
        } else if (object.teamOneHandler === true) {
            console.log("Handler of " + object.teamOne);
            logTeamTwo(object);
        } else {
            console.log("Member of " + object.teamOne);
            logTeamTwo(object);
        };
    };
};

var logRoster = function() {
    for (i = 0; i < rosterList.length; i++) {
        logObject(rosterList[i]);
        newLine(2);
    };
};

logRoster();

Unfortunately, when I run this code It crashes the page. I've double checked my loops multiple times, they're not infinite. Any suggestions?


#10

After hours of troubleshooting, I have determined that Object.keys(roster) is not behaving in the way I need it to. For instance, If I called logObject(roster.aqua); This is what the console shows:

Name: Aqua McCoolah
Gender: Male
Age: 21
Rank: General [★★★★★]
Nickname: Aqua Phoenix
Leader of The McCoolahs

However, If I called logObject(Object.keys(roster)[3]); Which, if I'm not mistaken is practically the exact same thing as the other line of code, the console will display this:

Name: undefined
Gender: undefined
Age: undefined
Rank: undefined
Nickname: undefined
Member of undefined
Member of undefined

As far as I can tell, Object.keys() appears to only store the names of the keys in an array. When I loop through that array, I'm only getting the name of the key and not an identifier for where it is located. For instance instead of roster.aqua it gives me aqua. However, in order for my code to work I need the former. Is there a way to fix this? I don't know if this has anything to do with my page crashing issue, but I know I need to fix it regardless.


#11

As I understand it, since an object is unordered, we cannot predict the order of the keys returned by this method.


#12

I actually managed to fix that part of my issue moments ago, ironically enough, by using logObject(roster[rosterList[3]]); instead.

Unfortunately, Now I'm back to that whole page crashing issue. Here is my updated code, just in case you would like to check it out, because I really do NOT know what to do about the page crashing.

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20,
        teamOne: "none",
        teamOnelLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "The Archer",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: true,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "The Admiral",
        age: 19,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky",
        age: 16,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: true,
        teamTwoHandler: false
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    }
};
var rosterList = Object.keys(roster);
var newLine = function(lines) {
    for (i = 0; i < lines; i++) {
        console.log();
    };
};
var logName = function(object) {
    return object.name;
};
var logTeamTwo = function(object) {
    if (object.teamTwo != "none") {
        if (object.teamTwoLeader == true) {
            console.log("Leader of " + object.teamTwo);
        } else if (object.teamTwoSecond == true) {
            console.log("Second-in-command of " + object.teamTwo);
        } else if (object.teamTwoHandler == true) {
            console.log("Handler of " + object.teamTwo);
        } else {
            console.log("Member of " + object.teamTwo);
        };
    };
};
var logObject = function(object) {
    console.log("Name: " + object.name);
    console.log("Gender: " + object.gender);
    console.log("Age: " + object.age);
    console.log("Rank: " + object.rank);
    console.log("Nickname: " + object.nickName);
    if (object.teamOne != "none") {
        if (object.teamOneLeader == true) {
            console.log("Leader of " + object.teamOne);
            logTeamTwo();
        } else if (object.teamOneSecond == true) {
            console.log("Second-in-command of " + object.teamOne);
            logTeamTwo();
        } else if (object.teamOneHandler === true) {
            console.log("Handler of " + object.teamOne);
            logTeamTwo();
        } else {
            console.log("Member of " + object.teamOne);
            logTeamTwo();
        };
    };
var logRoster = function() {
    for (i = 0; i < rosterList.length; i++) {
        logObject(roster[rosterList[i]]);
        newLine(2);
    };
};
logRoster();

#13

This may not be a problem, but for the sake of the reader, send an empty string.

console.log('');

Or accomplish this by constructing a string of newlines.

var newLine = function(lines) {
    var newlines = new Array(lines);
    for (var i = 0; i < lines; i++) {
        newlines[i] = "\n";
    }
    console.log(newlines.join('')); 
};

console.log('start');
newLine(3);
console.log('end');

start




end

#14

Um... not only was that a good idea, it totally fixed my infinite loop issue. What I'm not understanding, is why? Why did changing that of all things, fix my issue?

So, yeah... this is my updated (and apparently completely functional) code...

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20,
        teamOne: "none",
        teamOnelLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "The Archer",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: true,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "The Admiral",
        age: 19,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky",
        age: 16,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: true,
        teamTwoHandler: false
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    }
};
var rosterList = Object.keys(roster);
var newLine = function(lines) {
    var newlines = new Array(lines);
    for (var i = 0; i < lines; i++) {
        newlines[i] = "\n";
    }
    console.log(newlines.join('')); 
};
var logName = function(object) {
    return object.name;
};
var logObject = function(object) {
    console.log("Name: " + object.name);
    console.log("Gender: " + object.gender);
    console.log("Age: " + object.age);
    console.log("Rank: " + object.rank);
    console.log("Nickname: " + object.nickName);
    if (object.teamOne != "none") {
        if (object.teamOneLeader == true) {
            console.log("Leader of " + object.teamOne);
        } else if (object.teamOneSecond == true) {
            console.log("Second-in-command of " + object.teamOne);
        } else if (object.teamOneHandler == true) {
            console.log("Handler of " + object.teamOne);
        } else {
            console.log("Member of " + object.teamOne);
        };
    };
    if (object.teamTwo != "none") {
        if (object.teamTwoLeader == true) {
            console.log("Leader of " + object.teamTwo);
        } else if (object.teamTwoSecond == true) {
            console.log("Second-in-command of " + object.teamTwo);
        } else if (object.teamTwoHandler == true) {
            console.log("Handler of " + object.teamTwo);
        } else {
            console.log("Member of " + object.teamTwo);
        };
    };
};
var logRoster = function() {
    for (i = 0; i < rosterList.length; i++) {
        logObject(roster[rosterList[i]]);
        newLine(1);
    };
};
logRoster();

#15

This is what I ended up with:

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20,
        teamOne: "none",
        teamOnelLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "The Archer",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: true,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "The Admiral",
        age: 19,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky",
        age: 16,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: true,
        teamTwoHandler: false
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    }
};
var rosterList = Object.keys(roster);
var newLine = function(lines) {
    var newlines = new Array(lines);
    for (var i = 0; i < lines; i++) {
        newlines[i] = "\n";
    }
    console.log(newlines.join("")); 
};
var logName = function(object) {
    return object.name;
};
var logObject = function(object) {
    if (object.nickName != "N/A") {
        console.log("Name: " + object.name + " (" + object.nickName + ")");
    } else {
        console.log("Name: " + object.name);    
    }
    console.log("Rank: " + object.rank);
    console.log("Gender: " + object.gender);
    console.log("Age: " + object.age);
    if (object.teamOne != "none") {
        if (object.teamOneLeader === true) {
            console.log("Leader of " + object.teamOne);
        } else if (object.teamOneSecond === true) {
            console.log("Second-in-command of " + object.teamOne);
        } else if (object.teamOneHandler === true) {
            console.log("Handler of " + object.teamOne);
        } else {
            console.log("Member of " + object.teamOne);
        }
    }
    if (object.teamTwo != "none") {
        if (object.teamTwoLeader === true) {
            console.log("Leader of " + object.teamTwo);
        } else if (object.teamTwoSecond === true) {
            console.log("Second-in-command of " + object.teamTwo);
        } else if (object.teamTwoHandler === true) {
            console.log("Handler of " + object.teamTwo);
        } else {
            console.log("Member of " + object.teamTwo);
        }
    }
};
var logRoster = function() {
    for (i = 0; i < rosterList.length; i++) {
        logObject(roster[rosterList[i]]);
        newLine(1);
    }
};
logRoster();

And, while it works beautifully, I'm still quite confused...

Why did changing this:

var newLine = function(lines) {
    for (i = 0; i < lines; i++) {
        console.log();
    }
};

To this:

var newLine = function(lines) {
    var newlines = new Array(lines);
    for (var i = 0; i < lines; i++) {
        newlines[i] = "\n";
    }
    console.log(newlines.join('')); 
};

Stop my page from crashing when I ran the code?


#16

Is this code performing up to your expectations? If so, then you have a good start but should not stop there. How can we simplify and refine the code (refactor)? This is something that is often hard to do if we have creation blindness that shutters our objectivity. It's hard to be dissatisfied with something we have poured so much effort into. You'll get over it if you let yourself stand back and get critical of your work.

Consider the following:

    if (object.nickName != "N/A") {
        console.log("Name: " + object.name + " (" + object.nickName + ")");
    } else {
        console.log("Name: " + object.name);    
    }

Above we see the first segment logged in both branches, unconditionally, so why not log it first, then assess the nickname?

console.log("Name:", object.name, object.nickName != "N/A" ? "(" + object.nickName + ")" : '' );

Could the following be simplified by writing it as a switch statement?

    if (object.teamOne != "none") {
        if (object.teamOneLeader === true) {
            console.log("Leader of " + object.teamOne);
        } else if (object.teamOneSecond === true) {
            console.log("Second-in-command of " + object.teamOne);
        } else if (object.teamOneHandler === true) {
            console.log("Handler of " + object.teamOne);
        } else {
            console.log("Member of " + object.teamOne);
        }
    }

Eg.

if (object.teamOne != "none") {
    var s;
    switch (true) {
    case object.teamOneLeader: s = "Leader of"; break;
    case object.teamOneSecond: s = "Second-in-command of"; break;
    case object.teamOneHandler: s = "Handler of"; break;
    default: "Member of";
    }
    console.log(s, object.teamOne);
}

We've only just begun, if you get my meaning. The best person to take criticism from is often ourselves. We don't need to take offense or pull any punches. This is one of the hardest things you'll have to do as a programmer, but always pays in spades.


#17

Alright, I made your suggested changes, (I also added a few of my own) Tell me what you think:

var roster = {
    liv: {
        name: "Olivia Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Liv",
        age: 20,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    maddie: {
        name: "Maddie Rooney",
        rank: "Her Majesty, The Queen [♛]",
        gender: "Female",
        nickName: "Mad-Dog",
        age: 20,
        teamOne: "none",
        teamOnelLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    emma: {
        name: "Emma Ross",
        rank: "Her Majesty, The Princess [♛]",
        gender: "Female",
        nickName: "The Crimson Samurai",
        age: 19,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    aqua: {
        name: "Aqua McCoolah",
        rank: "General [★★★★★]",
        gender: "Male",
        nickName: "Aqua Phoenix",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mikayla: {
        name: "Mikayla McCoolah",
        rank: "General [★★★★]",
        gender: "Female",
        nickName: "Stabitha",
        age: 27,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    lynx: {
        name: "Lynx McCoolah",
        rank: "General [★★★]",
        gender: "Female",
        nickName: "The Archer",
        age: 21,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jack: {
        name: "Jack McCoolah",
        rank: "General [★★★]",
        gender: "Male",
        nickName: "The Rogue Shadow/The Defender",
        age: 20,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: true,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    scarlett: {
        name: "Scarlett McCoolah",
        rank: "General [★★]",
        gender: "Female",
        nickName: "Scar",
        age: 18,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    nile: {
        name: "Nile McCoolah",
        rank: "General [★★]",
        gender: "Male",
        nickName: "The Admiral",
        age: 19,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    chase: {
        name: "Chase Davenport",
        rank: "General [★★]",
        gender: "Male",
        nickName: "Master of Intelligence",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: true,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    bree: {
        name: "Bree Davenport",
        rank: "General [★]",
        gender: "Female",
        nickName: "Master of Speed",
        age: 19,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    adam: {
        name: "Adam Davenport",
        rank: "General [★]",
        gender: "Male",
        nickName: "Master of Strength",
        age: 23,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    leo: {
        name: "Leo Dulley",
        rank: "General [★]",
        gender: "Male",
        nickName: "Metal Limbs",
        age: 17,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    skylar: {
        name: "Skylar McCoolah",
        rank: "General [★]",
        gender: "Female",
        nickName: "Sky",
        age: 16,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: true,
        teamTwoHandler: false
    },
    skylarStorm: {
        name: "Skylar Storm",
        rank: "Colonel",
        gender: "Female",
        nickName: "Ms. Storm",
        age: 18,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: true,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    winter: {
        name: "Winter McCoolah",
        rank: "Colonel",
        gender: "Female",
        nickName: "Timebreaker",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    connor: {
        name: "Connor McCoolah",
        rank: "Colonel",
        gender: "Male",
        nickName: "Mr. Invulnerable",
        age: 15,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "The Royal Defenders",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    amber: {
        name: "Amber McCoolah",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "The Berserker",
        age: 14,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    kim: {
        name: "Kim Krawford",
        rank: "Lieutenant Colonel",
        gender: "Female",
        nickName: "Agent Krawford",
        age: 20,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    douglas: {
        name: "Douglas Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "N/A",
        age: 42,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    donald: {
        name: "Donald Davenport",
        rank: "Lieutenant Colonel",
        gender: "Male",
        nickName: "Big-D",
        age: 44,
        teamOne: "The Elite Force",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mahooma: {
        name: "Michael Mahooma",
        rank: "Major",
        gender: "Male",
        nickName: "Mahooma",
        age: 38,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    mason: {
        name: "Mason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "The Sasquatch",
        age: 40,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    jason: {
        name: "Jason McCoolah",
        rank: "Major",
        gender: "Male",
        nickName: "Mr. Reckless",
        age: 36,
        teamOne: "The McCoolahs",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    parker: {
        name: "Parker Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Doctor P",
        age: 16,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    ruby: {
        name: "Ruby Rooney",
        rank: "Captain",
        gender: "Female",
        nickName: "The Red Ribbon",
        age: 14,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    joey: {
        name: "Joseph Rooney",
        rank: "Captain",
        gender: "Male",
        nickName: "Falcon",
        age: 18,
        teamOne: "none",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: false,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    },
    thompson: {
        name: "Ash Thompson",
        rank: "Captain",
        gender: "Male",
        nickName: "Mercenary",
        age: 32,
        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false
    }
};
var rosterList = Object.keys(roster);
var newLine = function(lines) {
    var newlines = new Array(lines);
    for (var i = 0; i < lines; i++) {
        newlines[i] = "\n";
    }
    console.log(newlines.join("")); 
};
var logName = function(object) {
    return object.name;
};
var logObject = function(object) {
    console.log("Name:", object.name, object.nickName != "N/A" ? "(" + object.nickName + ")": "");
    console.log("Rank:", object.rank);
    console.log("Gender:", object.gender);
    console.log("Age:", object.age);
    if (object.teamOne != "none") {
        var t1;
        switch (true) {
            case object.teamOneLeader: t1 = "Leader of"; break;
            case object.teamOneSecond: t1 = "Second-in-command of"; break;
            case object.teamOneHandler: t1 = "Handler of"; break;
            default: "Member of";
        }
        console.log(t1, object.teamOne);
    }
    if (object.teamTwo != "none") {
        var t2;
        switch (true) {
            case object.teamTwoLeader: t2 = "Leader of"; break;
            case object.teamTwoSecond: t2 = "Second-in-command of"; break;
            case object.teamTwoHandler: t2 = "Handler of"; break;
            default: "Member of";
        }
        console.log(t2, object.teamTwo);
    }
};
var logRoster = function() {
    for (i = 0; i < rosterList.length; i++) {
        logObject(roster[rosterList[i]]);
        newLine(1);
    }
};
logRoster();

#18

The next thing to examine is the data structure. How do we dynamically create property names when we have two members with the same name? Answer: Don't use named objects is one way.

var roster = [];

Now we would write a constructor function to generate anonymous objects. Let's pretend for now it is a Member class.

function Member(args) {
    this.name = args[0];
    this.rank = args[1];
    // and so on...
}

With that in our tool kit we can append new members to the roster array.

roster.push(new Member(['argument list'])

The argument list will contain only the values, in the correct order. Your data could be stored in an array and then read in to the roster.

var members = [
    ["Leo Dulley", "General [★]", "Male", "Metal Limbs", 17, "The Elite Force",
     false, false, false, "none", false, false, false],
    [ 'and so on' ]
];

The nice thing about using a constructor function is that now all the objects are instances of the one class and can share methods. This also gives some closure. It means a major rewrite so do not change the above code model that you have. Save it and start again from scratch (should you decide to go this route).

[Edit]

Concerning the following from the earlier example,

object.nickName != "N/A" ?

if we set the nickName property to an empty string instead of "N/A" then this gets shortened to,

object.nickName ?

The same could be done with teamOne and teamTwo. Rather than "none", an empty string is falsy.


#19

How goes the rewrite? It is a bit of work, but the finished product will be much more self-contained, and as mentioned earlier, they all share a custom prototype, as opposed to just Object.prototype.

We can take advantage of Member.prototype by piling up all our methods in that object.

Take for instance the code that we earlier refactored to deal with these properties:

        teamOne: "The Royal Defenders",
        teamOneLeader: false,
        teamOneSecond: false,
        teamOneHandler: true,
        teamTwo: "none",
        teamTwoLeader: false,
        teamTwoSecond: false,
        teamTwoHandler: false

        switch (true) {
            case object.teamOneLeader: t1 = "Leader of"; break;
            case object.teamOneSecond: t1 = "Second-in-command of"; break;
            case object.teamOneHandler: t1 = "Handler of"; break;
            default: "Member of";
        }

Now consider, removing the three is a case attributes in and replacing them with a single attribute, role will simplify the constructor significantly, and the constructor function as a whole.

this.role = args[...];

The argument would be an array,

[ [`team name`, `role`], [`team name`, `role`] ]

If only on one team, then the other would contain null's.

Eg.

[["The Royal Defenders", "Handler"], [null, null]]

We could also use plain objects...

[{team: "The Royal Defenders", role: "Handler"}, {team: null, role: null}]

The line of reasoning here is based on sequential data, which in a small set is generally the simplest and most efficient approach. Large data sets are far less fixed, though that would be a whole different conversation, without me in it.

So far we have tinkered with the data set and the constructor, All that's left is to start drumming up the methods the data points will have in common.

Something I forgot to mention much earlier. We may open the program with a huge array that needs to be transferred to the roster as Member instances, but once the transfer takes place, we no longer need that array. To free up the memory it occupies, we would,

members = null;

and, poof, it is gone. And all that memory is recovered.

At some point we will want all this data in a JSON file so it doesn't occupy program memory and is an on demandI object out on a volume somewhere. But that is not for the present. Stay this present course, and build the data in the code source.

The instance object,

{
  this.name: "Ash Thompson",
  this.rank: "Captain",
  this.gender: "Male",
  this.nickName: "Mercenary",
  this.age: 32,
  this.roles:[{team:"The Royal Defenders",role:"Handler"},{team:null,role:null}]
}

would have been stored in the members array, as,

[
  ["Ash Thompson", "Captain", "Male", "Mercenary", 32,
   [{team: "The Royal Defenders", role: "Handler"}, {team: null, role: null}]
  ],
// ...
]

#20

In an earlier post we touched on falsy. null is falsy. It is also the value passed in an argument list between two commas.

rosters.push([..., ...., , ..., ...]);

The horizontal ellipses would be the values present, and the value between the two commas would be null. This is good to know when wanting to leave attributes falsy, such as nickName. Passing an empty string is so messy by comparison.

Apparently, I am full of it. Must needs be we give a value. And I was loving it, until I tried it. Gives us something to wonder.