j4pm/website/name.js
2022-04-01 22:47:58 -04:00

48 lines
1.2 KiB
JavaScript

const names = [
"sunset",
"luna",
"valerie",
"bonnie",
"artemis",
"diana",
"constanze",
"twilight",
"bianca",
"dawn",
"rosa",
"akemi",
];
function getNextName(current) {
let index = Math.floor(Math.random() * names.length);
//console.log(current, names[index])
if (names[index] === current) {
return getNextName(current);
}
return names[index];
}
function constructNewElement(currentName, nameElement) {
let newName = document.createElement("h3");
newName.setAttribute("id", "scroll");
newName.setAttribute("class", "monospace");
newName.innerText = getNextName(currentName);
nameElement.appendChild(newName);
}
function constructNameElement() {
let nameElement = document.querySelector("#name");
//console.log(nameElement)
constructNewElement("", nameElement);
setInterval(() => {
let firstChild = nameElement.firstChild;
let currentName = firstChild.innerText;
//console.log(firstChild, currentName)
constructNewElement(currentName, nameElement);
firstChild.remove();
}, 60000);
}
document.addEventListener("DOMContentLoaded", () => {
constructNameElement();
});