In order to demonstrate how facades can be used both to encapsulate complexity, helping us enforce the Separation of Concerns principle, and also abstract third-party library APIs into more convenient methods that are application centric, we are going to demonstrate a very simple lottery application. Our "Element Lottery" application will populate its container with some Lottery Ticket elements that will have a unique ID and contain a random number.

The winning ticket will be picked by randomly selecting one of the lottery elements, based on a random index among the created unique IDs. The winning number will then be announced to be the numeric content of the picked element. Let's see the modules of our application:
(function() { window.elementLottery = window.elementLottery || {}; var elementIDs; var $lottery; var ticketCount = 30; elementLottery.init = function() { elementIDs = []; $lottery = $('#lottery').empty(); elementLottery...