0

The program works perfectly on Visual Studio Code, but not sure Stackblitz. (I really need to use Stackblitz.)

The error message:

Identifier 'runTimers' has already been declared

The url Stackblitz is here => https://stackblitz.com/edit/web-platform-yaoyey?file=index.html

Thank you for your help.

elodie
  • 23
  • 3
  • Please include relevant code in the question itself, not linked to an external resource. As for the error itself, it's telling you that you're declaring something called `runTimers` twice (at least) in the same scope. You'd correct it by not doing that. Either re-use the same variable or choose a new name for the new variable. – David Jan 05 '23 at 16:34

2 Answers2

1

You declared a runTimers function in both eth.js and btc.js. You have access to any functions declared in a script file you loaded before the current one.

Adam Pearson
  • 304
  • 1
  • 7
1

As per your codebase in index.html, you have two script tags as follow:

<script src="btc.js"></script>
<script src="eth.js"></script>

Due to this, both btc.js and eth.js is imported and processed.

In btc.js, you have following at Line 25

let runTimers = setInterval(

And in eth.js, you have following at Line 25

let runTimers = setInterval(

So, the runTimer is declared twice, i.e. first btc.js is imported in index.html and the first runTimer variable is declared and cleared and after that eth.js is imported in index.html and it tries to create runTimer, which causes the error.

To fix this, simply rename the variables, which would avoid conflict and fix the issue.

Ashok
  • 2,411
  • 1
  • 13
  • 23