Created
October 21, 2014 05:08
-
-
Save glinesbdev/ff64067ace476eaf58e9 to your computer and use it in GitHub Desktop.
Craziness with JS objects and arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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