JSFiddle - React, Tailwind, and code Playground
by mschock
JavaScript
function Drone() {};
Drone.prototype.takeoff = function takeoff(callback) {
setTimeout(function() {
callback()
console.log('Took off');
}, 600);
};
Drone.prototype.turnOnCamera = function turnOnCamera(callback) {
setTimeout(function() {
callback()
console.log('Camera turned on');
}, 1000);
};
Drone.prototype.pointDownGimbal = function pointDownGimbal(callback) {
setTimeout(function() {
callback()
console.log('Gimbal pointing down');
}, 750);
};
Drone.prototype.flyToMission = function FlyToMission(callback) {
setTimeout(function() {
callback()
console.log('Flown to mission');
}, 2000);
};
Drone.prototype.takePhoto = function takePhoto(callback) {
setTimeout(function() {
callback()
console.log('Photo taken');
}, 500);
};
Drone.prototype.land = function land(callback) {
setTimeout(function() {
callback()
console.log('Landed');
}, 3000);
};
//DONT MODIFY ANYTHING ABOVE HERE
// START ADD YOUR CODE HERE
var drone = new Drone();
Drone.prototype.dequeueAndExecuteAction = function() {
if (this.queue.length) {
var action = this.queue.shift();
action();
}
}
function buildActionMethod(action) {
return function() {
if (!this.queue) {
this.initializing = true;
this.queue = [];
}
this.queue.push(
Drone.prototype[action].bind(
this, this.dequeueAndExecuteAction.bind(this)
)
);
if (this.initializing) {
this.dequeueAndExecuteAction();
this.initializing = false;
}
return this;
}
}
drone.takeoff = buildActionMethod('takeoff');
drone.turnOnCamera = buildActionMethod('turnOnCamera');
drone.pointDownGimbal = buildActionMethod('pointDownGimbal');
drone.flyToMission = buildActionMethod('flyToMission');
drone.takePhoto = buildActionMethod('takePhoto');
drone.land = buildActionMethod('land');
// END ADD YOUR CODE HERE
//DONT MODIFY ANYTHING BELOW HERE
console.log("Expected Output:")
console.log("Took Off");
console.log("Camera...