-4

So my ultimate goal here is to have the site have a new title each day (24 hours).

I am not a very experienced program, but, I am aware something similar could be done with JS.

I saw this idea:

setInterval(function() {
    //change title
    //document.title = "Some new title";
}, 3000);

I'm not sure how I can take this idea above, which I do not fully understand and make it use, for example, a large array or predefined titles and select one at random each day.

Would it be possible to select the title out of another file or should I have them all in the JS file? On the question just asked, should I have the JS code in the HTML file itself or referenced as a file like a CSS file?

I really appreciate any walkthrough/help I can get on this. I hope your days are well all.

Orangepaw3
  • 19
  • 7
  • 2
    Do you expect most people using your site to have it open for 24 hours continuously? – John Montgomery Dec 13 '19 at 20:03
  • @JohnMontgomery There was obviously no thought process about how people use the web. – gforce301 Dec 13 '19 at 20:16
  • In answer to your 1st two questions contained in one: (1) yes, (2) if you want. In answer to your 2nd two questions contained in one: (1) sure why not, (2) that works also. SO is not a _write some code for me for free site_. It's also not a _teach me an entire course on web technologies, so that I can answer my own simple questions about something that once I have the knowledge I would never consider doing_. It is **expected** that you have some basic knowledge of what you are trying to do and that you have **attempted** to do it. Voting to close. – gforce301 Dec 13 '19 at 20:22
  • No, I would expect they return on another day however. Some websites such as wowhead.com a very popular website, already use similar ideas however. Thank you @gforce301 for being snide. – Orangepaw3 Dec 13 '19 at 20:36

1 Answers1

1

found the solved problem with running code once per day: Run code once a day

When you will have a function that runs once per day, you just have to reference the title from DOM inside the function and define new title.

var titles = ["title1", "title2", "title3"];
var iterator = 0; // this variable should be incremented every day

// somewhere inside the function that runs once per day
document.title = titles[iterator];

There are 2 ways to import a script on html page.

Inline: https://www.w3schools.com/tags/tag_script.asp

External: https://www.w3schools.com/tags/tag_link.asp

U can even read external file (.txt e.g.) in js, you can look that up, but it's bit more complicated than this.