var symbolName = 'Facebook Inc.';
var symbol = 'AAPL';
document.addEventListener('DOMContentLoaded', () => {
// https://financialmodelingprep.com/developer/docs
getRequest(
'https://financialmodelingprep.com/api/v3/company-key-metrics/' + symbol + "?apikey=demo",
drawOutput
);
function drawOutput(responseText) {
let resp = JSON.parse(responseText);
let symbol = resp.symbol;
let financials = resp.metrics;
let $table = document.createElement("table");
$table.className += " table";
var elements = document.querySelectorAll('.stock-name')[0];
let $head = document.createElement("thead");
let $body = document.createElement("tbody");
let $lineHader = document.createElement("tr");
for (let i = 0; i < financials.length; i++) {
let financial = financials[i];
let $line = document.createElement("tr");
for (var key in financial) {
if (i === 0 && financial.hasOwnProperty(key)) {
let $ele = document.createElement("th");
$ele.textContent = key;
$lineHader.appendChild($ele);
}
}
$head.appendChild($lineHader);
$table.appendChild($head);
for (var key2 in financial) {
if (financial.hasOwnProperty(key2)) {
let $eletd = document.createElement("td");
$eletd.textContent = financial[key2];
$line.appendChild($eletd);
}
}
$body.appendChild($line)
$table.appendChild($body);
}
document.body.appendChild($table);
}
function getRequest(url, success) {
var req = false;
try {
req = new XMLHttpRequest();
} catch (e) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
return false;
}
}
}
if (!req) return false;
if (typeof success !=...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.