I am trying to get price from website and I get NaN error as output.
Website link and path correct because i tested it in python with different script
const request = require('request');
const cheerio = require('cheerio');
function calculateCrypto(type, USD) {
let typeString = '';
if (type === 'ETH') {
typeString = 'ethereum';
} else if (type === 'BTC') {
typeString = 'bitcoin';
} else if (type === 'LTC') {
typeString = 'litecoin';
}
const url = `https://bitflyer.com/en-us/${typeString}-chart`;
request(url, (error, response, html) => {
if (!error && response.statusCode == 200) {
const $ = cheerio.load(html);
const OneCryptoCostwspaces = $('.p-currencyInfo__price c-text--number').text();
const OneCryptoCost = OneCryptoCostwspaces.replace(/ /g, '').replace('*USD', '').replace(/,/g, '');
const OneCryptoCostDouble = parseFloat(OneCryptoCost.trim());
const oranti = OneCryptoCostDouble / USD;
const cryptoDue = 1 / oranti;
console.log(cryptoDue);
}
});
}
calculateCrypto('ETH', 10000);
I’m trying to get the amount equivalent to the specified money