0

I'm a beginner in JavaScript. I'm trying to embed some code from external website. The embedded code works fine in my webpage . However, a JSON object that is defined in the script tag causes problems of semicolon expectations in the VS Code.Program works properly even with errors. What should I do to get rid of these errors ?

MY CODE :

<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
  <div class="tradingview-widget-container__widget"></div>

  <script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-forex-cross-rates.js" async>
    {
      "width": "800",
      "height": "500",
      "currencies": [
        "EUR",
        "USD",
        "JPY",
        "GBP",
        "CHF",
        "AUD",
        "CAD",
        "NZD",
        "CNY",
        "TRY",
        "SEK",
        "NOK",
        "DKK",
        "ZAR",
        "HKD",
        "SGD",
        "THB",
        "MXN",
        "IDR",
        "KRW",
        "PLN",
        "ISK",
        "KWD",
        "PHP",
        "MYR",
        "INR",
        "TWD",
        "SAR",
        "AED",
        "RUB",
        "ILS",
        "ARS",
        "CLP",
        "COP",
        "PEN",
        "UYU"
      ],
      "isTransparent": false,
      "colorTheme": "light",
      "locale": "en"
    }
  </script>
</div>
<!-- TradingView Widget END -->

enter image description here

Semicolon are expecting instead of colons such as "width":"800". Colons(:) are underlined with red color.

When I tried to declare that object with a name such as var a = {}, errors are disappearing however embedded code is not working.

Teemu
  • 22,918
  • 7
  • 53
  • 106
  • 1
    You can't just put an object literal to a code without assigning it to a variable. `{` is interpreted to start a code block, and the code inside the block is syntactically incorrect. – Teemu Dec 07 '21 at 20:00
  • 1
    JSON is not JavaScript. If you put the data into a script it's no longer JSON. If the script works, you might just be able to ignore the errors, since VS Code doesn't like the approach it has taken. – evolutionxbox Dec 07 '21 at 20:01
  • 3
    If you have `script src="..."`, you can't have content in the script and vice versa. Also, change the script type to `application/json`. – code Dec 07 '21 at 20:03
  • 1
    Maybe this might help https://stackoverflow.com/questions/6528325/what-does-a-script-tag-with-src-and-content-mean? – evolutionxbox Dec 07 '21 at 20:04

0 Answers0