Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Extension Google Chrome Create..

const baseCoinAPI = "https://pro-api.coinmarketcap.com/";
const apiVersion = "v1";
const apiKey = `&CMC_PRO_API_KEY=${REACT_APP_CMC_KEY}`;

//Function to get the top 25 coins.
const getCoins = async (endPoint) => {
  let path = `${baseCoinAPI}${apiVersion}${endPoint}${apiKey}`;
  const fetchResult = await fetch(path);
  const result = await fetchResult.json();

  if (fetchResult.ok) {
    return result;
  }
  const responseError = {
    type: "Error",
    message: result.message || "Something went wrong",
    data: result.data || "",
    code: result.code || "",
  };

  let error = new Error();
  error = { ...error, ...responseError };
  throw error;
};

//DOM Manipulation to show all the coins and respective values
const coins = getCoins("/cryptocurrency/listings/latest?limit=25");
var mainContent = document.getElementById("main-content");
if (coins.length > 0) {
  coins.forEach((coin) => {
    var content = document.createElement("div");
    var paragraph = document.createElement("p");
    paragraph.textContent = `${coin.name} - ${coin.quote.USD.price}`;
    content.appendChild(paragraph);
    mainContent.appendChild(content);
  });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: validate on submit not working 
Javascript :: mongoose match aggregate 
Javascript :: react custom hooks 
Javascript :: how to create variables using javascript 
Javascript :: npm mongoose findorcreate 
Javascript :: jconfirm button 
Javascript :: buttons js before submit 
Javascript :: fastify testing 
Javascript :: javascript filter 2d array 
Javascript :: javascript onsubmit change input value 
Javascript :: javascript sucks 
Javascript :: luhn algorithm javascript 
Javascript :: javascript merge two sorted arrays 
Javascript :: jquery direct window print pdf 
Javascript :: define conastant js 
Javascript :: emit event to a single socket id in socket 
Javascript :: dual array in javascript 
Javascript :: print name time times in javascript 
Javascript :: #{10000000000000000000000000000000000} js 
Python :: check if tensorflow gpu is installed 
Python :: drop the last row of a dataframe 
Python :: display maximum columns pandas 
Python :: how to use headless browser in selenium python 
Python :: get terminal size python 
Python :: use nltk to remove stop words 
Python :: install docx python 
Python :: get stats from array python 
Python :: python get stack trace 
Python :: accuracy score sklearn syntax 
Python :: get text from txt file python 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =