diff --git a/js/common.js b/js/common.js index 66083c4..03df554 100644 --- a/js/common.js +++ b/js/common.js @@ -16,46 +16,40 @@ /** Displays splash text under heading. Runs forever.*/ async function splashtext() { const sayings = [ + "We are the Dearborn differenceâ„¢", + "Hands-on Learning, Real World Impact", + "Robotic googly eye innovators", "\"Do something worth being here for\"", "Home of Henry", - "Robotic googly eye innovators", + "Education. Opportunity. Growth.", + "Go Blue!", + "Engineering solutions, not just robots", "Anderson connector enthusiasts", "Sometimes the things we build are smart", + "Automation with a human touch", "Our karts race themselves", - "Go Blue!", - "Engineering solutions, not just robots", + "Creators of the autonomous Desert Bus", "Robotics isn't a hobby, its a lifestyle", - "Automation with a human touch", "Where every challenge is an opportunity", - "Proud supporters of open source robotics", - "Hands-on Learning, Real World Impact", - "Education. Opportunity. Growth.", - "We are the Dearborn differenceâ„¢" + "Proud supporters of open source robotics" ]; - let lastRand = 0 - let tag = document.getElementById("splash-text") + let index = Math.floor(Math.random() * sayings.length); + let direction = 1; // 1 for forward, -1 for backward + let tag = document.getElementById("splash-text"); // noinspection InfiniteLoopJS while (true) { - //Cycle rand to avoid the same saying twice - let rand - while (true) { - rand = Math.floor(Math.random() * sayings.length) - if (rand !== lastRand) { - break; - } - } - lastRand = rand + - const saying = sayings[rand] + const saying = sayings[index] let current = "|" //Type each letter individually for (const l of saying) { current = current.slice(0, current.length - 1) + l + '|' tag.innerText = current - await sleep(22) + await sleep(18) //22 } //Blink for a bit @@ -73,7 +67,7 @@ async function splashtext() { current = current.slice(0, current.length - 2) + '|' tag.innerText = current - await sleep(19) + await sleep(13) //19 } //Blink for a bit @@ -86,6 +80,18 @@ async function splashtext() { await sleep(400) } + // Move to the next index, either forward or backward + index += direction; + + // If we reach the end or the beginning, reverse direction + if (index >= sayings.length) { + index = sayings.length - 2; // Avoid repeating last element + direction = -1; // Reverse direction + } else if (index < 0) { + index = 1; // Avoid repeating first element + direction = 1; // Forward direction + } + } //End while } //End fn