-
Notifications
You must be signed in to change notification settings - Fork 0
/
name.js
41 lines (32 loc) · 1.01 KB
/
name.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const name = getNameFromUrl() || "Keine Argumente angegeben!";
const nameEle = document.getElementById("name");
const ylno = document.getElementById("ylno");
const greetings = document.getElementById("greetings");
createNameSpans(name);
const letterEles = document.querySelectorAll(".letter");
console.log(letterEles);
lightUpName(1);
function createNameSpans(name) {
let nameArray = name.split("");
let htmlString = "";
nameArray.forEach((letter, index) => {
htmlString += `<span class="letter" id="letter-${index}">${letter}</span>`;
});
nameEle.innerHTML = htmlString;
}
function lightUpName(n) {
let length = letterEles.length;
for (let i = 0; i < length; i++) {
let ele = letterEles[i];
ele.className = (n + i) % 2 == 0 ? "green" : "red";
}
setTimeout(function () {
lightUpName(n + 1);
}, 500);
}
function getNameFromUrl() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
let urlName = urlParams.get("n");
return urlName;
}