Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Created October 21, 2014 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glinesbdev/ff64067ace476eaf58e9 to your computer and use it in GitHub Desktop.
Save glinesbdev/ff64067ace476eaf58e9 to your computer and use it in GitHub Desktop.
Craziness with JS objects and arrays
// Without running the code in the console, can you tell what this will do?
var superBlinders = [ ["Firestorm", 4000], ["Solar Death Ray", 6000], ["Supernova", 12000] ];
var lighthouseRock = {
gateClosed: true,
weaponBulbs: superBlinders,
capacity: 30,
secretPassageTo: "Underwater Outpost",
numRangers: 3,
ranger1: {name: "Nick Walsh", skillz: "magnification burn", station: 2},
ranger2: {name: "Drew Barontini", skillz: "uppercut launch", station: 3},
ranger3: {name: "Christine Wong", skillz: "bomb defusing", station: 1}
};
function dontPanic(location) {
var list = "";
for (var i = 1; i < location.numRangers; i++) {
list += location["ranger" + i].name + ", man the " + location.weaponBulbs[location["ranger" + i].station - 1][0] + "!\n";
}
alert("Avast, me hearties!\n" +
"There be Pirates nearby! Stations!\n" + list);
}
dontPanic(lighthouseRock);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment