Categories: Uncategorized

Returning Functions and Immediate Invocation

// ride and wait time
var parkRides = [["birch bumpers", 40], ["dank bumpers", 36], ["trap bumpers", 41], ["wtf bumpers", 43],];
// fast pass for faster line
var fastPassQueue = ["birch bumpers", "dank bumpers", "trap bumpers", "wtf bumpers"];
// allRides arg - this parameter will be the array of the rides and their wait time
// passrides arg - this will be the array of the nxt available fast pass rides
// pick arg - this will be the actual ride for which our customer would like a ticket!
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 +"!"); 
 };
 } else {
  for(var i =0; i<allRides.length;i++){
   if(allRides[i][0]==pick){
    return function () {alert("A ticket is print for " + pick +"!\n" + "Your wait time is about " + allRides[i][1] + " minutes.");
    };
   }
  }
 }
}
var wantsRide = "birch bumpers";
// self invoking function when you add () at the end off the function
buildTicket(parkRides, fastPassQueue, wantsRide)();

 

This is hypothetical fast pass system created with functions, arrays, conditional, and for loop statement. All written javascript.

Admin

Recent Posts

Unveiling the Intricacies of the Tinder Algorithm: 5 Surprising Metrics

Monitored by Tinder The inner workings of the Tinder algorithm remain shrouded in secrecy, known…

3 weeks ago

Is Shopping Temu Safe

Use fav19073 30% OFF Shop Now I recently had a fantastic buying experience on Temu,…

4 months ago

Cheap Netflix Subscription

Unlocking Affordable Streaming: How Gamsgo.com is Revolutionizing Netflix Subscriptions Sign Up Save1 coupon code for…

4 months ago

Domains for SALE.

razerkeyb.com gloriousmouse.com

9 months ago

How to Start your own vegetable garden?

Planting your own vegetables and fruit is a great way to save money and eat…

1 year ago

Jobs AI can’t replace

While AI has the potential to automate many tasks, there are still some jobs that…

1 year ago