soo u can see my code here what i want to do just want to call the variable
usdprice
in loginfunction which is in under getprice function and do some computation to get value of my token ,
value means usd price of cpt token * balance of cpt of any user see last line of login function
async function login() {
let currentuser = Moralis.User.current();
if (!currentuser) {
currentuser = await Moralis.authenticate({ signingMessage: "welcome to crypto planet " })
}
console.log("logged in user:", currentuser);
console.log(currentuser.get('ethAddress'));
let bal=currentuser.get('ethAddress')
document.getElementById("btn-login").innerHTML=bal;
// document.getElementById("hi").innerHTML = 'ethaddress';
const tokenBalance = usercptBalance()
tokenBalance.then(
function (value) {
console.log(value);
const t =Moralis.Units.FromWei(value);
document.getElementById("cpt").innerHTML = t;}
document.getelementbyid("value).innerhtml = t * usdprice ;
);
// cpt price
async function getPrice() {
price= await Moralis.Web3API.token.getTokenPrice({address: "0x28e4f32fa7e842ad0a6e530bb6b4ec03b36d5078", chain: "bsc"})
console.log(price);
let ethPrice = (price.nativePrice.value / (8**price.nativePrice.decimals)) + "BNB"
console.log(ethPrice)
let usdPrice = price.usdPrice ; *this is price of token which i want to call in login function*
console.log(usdPrice)
document.getElementById("BNB_price").innerHTML = ethPrice;
document.getElementById("usd_price").innerHTML = usdPrice;
}
getPrice();
// bnb price
async function takePrice() {
price= await Moralis.Web3API.token.getTokenPrice({address: "0x3ee2200efb3400fabb9aacf31297cbdd1d435d47", chain: "bsc"})
console.log(price);
let usdPrice = price.usdPrice
console.log(usdPrice)
document.getElementById("usd1").innerHTML = usdPrice;
}
takePrice();
// cardano price
async function givePrice() {
price= await Moralis.Web3API.token.getTokenPrice({address: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", chain: "bsc"})
console.log(price);
let usdPrice = price.usdPrice
console.log(usdPrice)
document.getElementById("usd2").innerHTML = usdPrice;
}
givePrice();