Timezone JS function

I am wanting to get this function to work to display the timezone in the footer of my webpage. As of now, when the webpage is loaded, the timezone does not appear in the footer of the webpage as intended.

This is what I have for JS script:

// This function displays the timezone.

function timezoneName() {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log(timezone);
document.getElementById("timezone").innerHTML = timezone;
}
timezoneName();

This is what I have for .html footer:

<footer>
<p id="timezone"></p>
</footer>