Created
July 30, 2014 03:05
-
-
Save pedromcunha/2dd37cfee80790b1572a to your computer and use it in GitHub Desktop.
Function Expressions and Instant Invocations.
This file contains hidden or 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
var listOfSharks = ["Sea Pain", "Great Wheezy", | |
"DJ Chewie", "Lil' Bitey", | |
"Finmaster Flex", "Swim Khalifa", | |
"Ice Teeth", "The Notorious J.A.W."]; | |
var listOfTargets = ["icicle bat", "snow yeti", | |
"killer penguin", "frost tiger", | |
"polar bear", "iceberg", | |
"blue witch", "wooly mammoth"]; | |
function makeTargetAssigner( sharks, targets ){ | |
return function (shark) { | |
var target = ''; | |
for (var i = 0; i < sharks.length;i++) { | |
if (sharks[i] == shark) { | |
target = targets[i]; | |
} | |
} | |
alert( | |
"What up, "+shark+"!\n" + | |
"There've been "+target+" sightings in our 'hood!\n" + | |
"Time for a swim-by lasering, homie!"); | |
}; | |
} | |
var getTargetFor = makeTargetAssigner(listOfSharks, listOfTargets); | |
getTargetFor("Ice Teeth"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment