skip to Main Content

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.

2

Answers


  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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search