var Messager = function() { this.warning = function(message) { console.warn(message); notice(message, "warning", 2000); }; this.transmission = function(message) { console.log(message); notice(message, "transmission", Math.max(message.length * 45, 2000)); }; var notice = function(message, displayType, duration) { var popup = document.createElement("div"); popup.className = "popup " + displayType; popup.style = "border-radius: 5px;"; document.getElementById("popupContainer").appendChild(popup); popup.innerHTML = message; popup.display = "block"; setTimeout(function() { document.getElementById("popupContainer").removeChild(popup); }, duration); }; } var messager = new Messager();