Last active
August 29, 2015 14:14
-
-
Save appkr/d3398600d4e055e47e7a to your computer and use it in GitHub Desktop.
JavaScript Ticketing Example// source http://jsbin.com/lapaca
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
var parkRides = [ | |
["Birch Bumper", 40], | |
["Pines Plunge", 55], | |
["Cedar Coaster", 20], | |
["Ferries Whell of Fires", 90] | |
]; | |
var fastPassQueue = [ | |
"Cedar Coaster", | |
"Pines Plunge", | |
"Birch Bumper", | |
"Pines Plunge" | |
]; | |
function buildTicket(allRides, passRides, pick) { | |
if (passRides[0] == pick) { | |
var pass = passRides.shift(); | |
return function() { | |
alert("Quick! You've got a Fast Pass to " + pass + "!"); | |
console.log(passRides); | |
}; | |
} else { | |
for(var i = 0, len = allRides.length; i < len; i++) { | |
if (allRides[i][0] == pick) { | |
return function() { | |
alert("A ticket is printing for " + pick + "!\n" + "Your wait time is about " + allRides[i][1] + " minutes."); | |
console.log(passRides); | |
}; | |
} | |
} | |
} | |
} | |
var wantsRide = "Birch Bumper"; | |
// Self invoking anonymous function | |
buildTicket(parkRides, fastPassQueue, wantsRide)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment