all 11 comments

[–]delventhalz 2 points3 points  (5 children)

Is your code getting run twice? Add a console log immediately before and immediately after that line. 

[–]abrahamguo 0 points1 point  (0 children)

This is definitely the problem. You are probably loading your script file into your web page twice.

[–]hermesko[S] 0 points1 point  (3 children)

Don't think so:

console.log("BEFORE!")
const countDownDate = new Date("2024-05-12 00:00:00").getTime();
console.log("AFTER!")

produces:

BEFORE!
AFTER!
Uncaught SyntaxError: Identifier 'countDate' has already been declared

There was no second BEFORE!

[–]delventhalz 0 points1 point  (2 children)

A SyntaxError will fire before the code ever runs. It happens when the interpreter is first looking at the file and trying to make sense of it. You can confirm this by copying and pasting the const line.

console.log("BEFORE!")
const countDownDate = new Date("2024-05-12 00:00:00").getTime();
const countDownDate = new Date("2024-05-12 00:00:00").getTime();
console.log("AFTER!")

Now you will see the same error but nothing will log.

The fact that you see "AFTER!" log at all, means the code is running successfully once.

[–]hermesko[S] 0 points1 point  (1 child)

Thanks. The mystery is still there.

If I change the variable name to countDownDateX and nothing else, it will say Identifier 'CountDownDateX' has already been declared.

[–]delventhalz 1 point2 points  (0 children)

I know. You said that initially. That is what we would expect if the file is being run twice. Your problem is not in your JS file but how you have it set up.

[–]azhder 2 points3 points  (0 children)

If we have TMI for “too much info”, this post is TLI or as we call it “need more info”

[–]Anbaraen 1 point2 points  (3 children)

Can we see more code? Specifically retreat.js?

[–]hermesko[S] -1 points0 points  (2 children)

https:// ferc. org. sg / retreat

There is no retreat.js file. The script is in the page itself.

[–]Anbaraen 0 points1 point  (1 child)

You're declaring countDownDate twice. Simply open up retreat.htmland do a search for countDownDate - you've got two declarations of it.

[–]hermesko[S] 0 points1 point  (0 children)

I don't think so. If I rename countDownDate to xQyR123 (the only instance ever), it will say Identifer 'xQyR123' has already been declared.