How to add javascript to an html card?

I am trying to create my first blog post using the ghost editor. I need to add some dynamic content in the title e.g. “How to make a good youtube video in 2023”. However, I want the year in the title (2023) to be dynamic so that I don’t need to manually update it when will be in 2024.

I tried to add the title as an HTML card but it doesn’t work

       <h1 id="year"></h1>
         var dt = new Date();
          var year = document.getElementById("year")
          year.innerHTML = dt.getFullYear()

Nothing is displayed. It seems only the HTML is recognized, not the javascript.

Do i make something wrong ?

An HTML card adds HTML to the page. It doesn’t replace existing HTML.

To accomplish this, you’ll need to target the existing title element on the page. Then, use Code Injection in the post’s sidebar to run JS to update the site title. Note, too, that your current code will change the title to just the year (“How to make…” → “2023”). You’ll need to update the code to generate the full title.