JSFiddle - React, Tailwind, and code Playground

by jack gold

HTML

<button data-floor="1">1</button>
<button data-floor="2">2</button>
<button data-floor="3">3</button>
<div class="log">***</div>

JavaScript

Elevator = (function() {

var currentFloor = 1,
    destination = 1,
    isMoving = false,
    direction = null,
    
    
    getDestination = function(trigger) {
        return $(trigger).attr('data-floor');
    },
    
    activateElevator = function(event) {
        
        var trigger = $(this),
            newDest = getDestination(trigger);
        
        
        
        isMoving = true;
        destination = newDest;
        updateLog();
    },
    
    updateLog = function() {
        $('.log').text('Destination:' + destination);
    },
    
    bindEvents = function() {
        $('button').on('click', activateElevator);
    },
    
    init = function() {
        bindEvents();
    };
    
    return {
        init: init
    }

})();

Elevator.init();