Search code examples
javascriptmathvar

how to times (x) a variable getting error


i have very small code which shows a coin price but i want to show it 2x times like 2 x coinprice i tried but it didn't show the value how can i show it i used let live = 2 * livePrice; but didn't work

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
  </head>

  <body translate="no">
    <h2>Current price :</h2>
    <h2 id="live"></h2>

    <script id="rendered-js">
      const live = document.getElementById("live");

      fetch("https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD&e=Coinbase")
        .then((res) => res.json())
        .then((data) => {
          let livePrice = data.RAW.ETH.USD.PRICE;
          let dayPrice = data.RAW.ETH.USD.OPEN24HOUR;

          let p = parseFloat(((livePrice - dayPrice) / dayPrice) * 100).toFixed(2);

          live.innerHTML = `<h2>${livePrice}</h2>`;
        });
      //# sourceURL=pen.js
    </script>
  </body>
</html>


Solution

  • Try this

    fetch("https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD&e=Coinbase")
            .then((res) => res.json())
            .then((data) => {
              let livePrice = data.RAW.ETH.USD.PRICE;
              let dayPrice = data.RAW.ETH.USD.OPEN24HOUR;
    
              let p = parseFloat(((livePrice - dayPrice) / dayPrice) * 100).toFixed(2);
    
              live.innerHTML = `<h2>${livePrice * 2}</h2>`;
            });