Display javascript items one by one and have different delays

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Display javascript items one by one and have different delays



I have a header on an HTML page and I want to cycle once through a String array, and I got that down. But now my question is if it is possible to have a longer delay on one or two specific array items?



my code:


var sentences = [ "1", "2", "3", "4", "5"];
var n = 0;

setInterval(function()
document.getElementById("headerCH").innerHTML = sentences[n++];
, 1000);





You also have problem of overshooting length of array. What is expectation when you run out of sentences?
– charlietfl
29 secs ago




1 Answer
1



You can multiply the time with any value




var sentences = ["Contacting Database...",
"Connection established",
"Use hash to decrypt Security Code",
"Security code gained",
"Security code verified",
"Indexing chats and media",
"Indexing finished",
"Compressing information",
"Uploading to ChatControl DB",
"Setting up account for user",
"User account complete"
];
var n = 0;

setInterval(function()
console.log(sentences[n++].length)
document.getElementById("headerCH").innerHTML = sentences[n++];
, sentences[n++].length * 300);


<div id='headerCH'></div>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS