function exchangeDataShow() { fetch('https://api.coinmarketcap.com/v1/ticker/?limit=20') .then( (responce) => { return responce.json(); }) .then( (data) => { let output = ' '; data && data.forEach(coin => { let rateChangeHour = coin.percent_change_1h < 0 ? 'rate-red' : 'rate-green'; let rateChangeDay = coin.percent_change_24h < 0 ? 'rate-red' : 'rate-green'; let rateChangeWeek = coin.percent_change_7d < 0 ? 'rate-red' : 'rate-green'; output += ` <tr> <td>${coin.rank}</td> <td>${coin.name}</td> <td>${coin.price_usd}</td> <td>${coin['24h_volume_usd']}</td> <td>${coin.market_cap_usd}</td> <td>${coin.total_supply}</td> <td>${coin.max_supply}</td> <td class="${rateChangeHour}">${coin.percent_change_1h}%</td> <td class="${rateChangeDay}">${coin.percent_change_24h}%</td> <td class="${rateChangeWeek}">${coin.percent_change_7d}%</td> </tr> `; }); document.getElementById('market-data').innerHTML = output; }) .catch( (err) => { console.log(err); }); } window.onload = exchangeDataShow(); setInterval(() => { console.log('reload'); exchangeDataShow(); }, 5000);
<td>${coin.max_supply||""}</td>