function createToast(heading = "No heading", message = "No message") { //Create empty variable for toasts container let container; //If container doesn't already exist create one if (!document.querySelector("#toast-holder")) { container = document.createElement("div") container.setAttribute("id", "toast-holder"); document.body.appendChild(container); } else { // If container exists asign it to a variable container = document.querySelector("#toast-holder"); } //Create our toast HTML and pass the variables heading and message let toast = `<div class="single-toast fade-in"> <div class="toast-header"> <span class="toast-heading">${heading}</span> <a href="#" class="close-toast">X</a> </div> <div class="toast-content"> ${message} </div> </div>`; // Once our toast is created add it to the container // along with other toasts container.innerHTML += toast; } createToast(); createToast("This is heading", "This is the message");