// Step 1: Scrape GDP data from Wikipedia const wikipediaUrl = "https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)"; const response = await fetch(wikipediaUrl); const html = await response.text(); const parser = new DOMParser(); const doc = parser.parseFromString(html, "text/html"); // Find the table containing GDP data const gdpTable = doc.querySelector(".wikipedia"); const rows = Array.from(gdpTable.querySelectorAll("tr")).slice(1); // Skip the header row // Create an object to store country GDPs const countryGdp = {}; rows.forEach((row) => { const columns = row.querySelectorAll("td"); const countryName = columns[1].textContent.trim(); const gdpValue = parseFloat(columns[2].textContent.replace(/,/g, "").replace("$", "")); countryGdp[countryName] = gdpValue; }); // Step 2: Scrape billionaires' wealth data from Forbes const forbesUrl = "https://www.forbes.com/real-time-billionaires/#72cc12ac3d78"; const forbesResponse = await fetch(forbesUrl); const forbesHtml = await forbesResponse.text(); const forbesDoc = parser.parseFromString(forbesHtml, "text/html"); // Find the table containing billionaire data const billionaireTable = forbesDoc.querySelector(".rtb-table"); const billionaireRows = Array.from(billionaireTable.querySelectorAll("tr")).slice(1); // Skip the header row // Create an array to store billionaire wealth const billionaireWealth = billionaireRows.map((row) => { const columns = row.querySelectorAll("td"); const wealthStr = columns[2].textContent.trim().replace("$", "").replace("B", ""); return parseFloat(wealthStr); }); // Step 3: Calculate the comparison const totalBillionaireWealth = billionaireWealth.reduce((sum, wealth) => sum + wealth, 0); const countriesNeeded = Object.keys(countryGdp).filter((country) => countryGdp[country] < totalBillionaireWealth).length; const gdpSum = Object.values(countryGdp).reduce((sum, gdp) => sum + gdp, 0); console.log("Total billionaire wealth:", totalBillionaireWealth); console.log("Countries needed to match billionaire wealth:", countriesNeeded); console.log("Sum of GDPs:", gdpSum);
top of page

About chillbelowzero.com

Biography

Over the years, I’ve had the chance to work with great companies. From setting strategic marketing goals, to customer experience strategies, I carefully review the needs of each client and tailor my work accordingly.

I started out in my field in 2000, and since then I’ve gathered the skills and expertise necessary to take you to the next level. Browse my Affiliate Marketing Portfolio to get a better idea of the kind of work I’ve been involved with. Want to learn more? Get in touch today.

Sync Up
bottom of page