Присвоить результат выполнения функции в переменную

у меня есть функция:

function getCoefficient(e) {
    return  fetch( 'https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/usd.json')
        .then(response => response.json())
        .then(data => data.usd[e]);
}

и я хочу что бы после ее вызова результат присваивался в переменную coefficient, для использования в дальнейшей логике программы, но в таком виде:

let prices = document.getElementsByClassName('products-item-price')
document.getElementById('change-currency').onclick = function (e) {
    let currentCurrency = e.target.innerText;
    let newCurrency = '$';
    let coefficient = 1;
    if (currentCurrency === '$') {
        newCurrency = '₽';
        coefficient = getCoefficient('rub')
    } else if (currentCurrency === '₽'){
        newCurrency = 'BYN';
        coefficient = getCoefficient('byn');
    } else if (currentCurrency === 'BYN'){
        newCurrency = '€';
        coefficient = getCoefficient('eur');
    } else if (currentCurrency === '€'){
        newCurrency = '¥';
        coefficient = getCoefficient('yen');
    }

    e.target.innerText = newCurrency;
    for (let i = 0; i < prices.length; i++) {
        prices[i].innerText = +(prices[i]
            .getAttribute('data-base-price') * coefficient)
            .toFixed(1) + ' ' + newCurrency;
    }
}

в переменную присваивается Nan Подскажите, пожалуйста, что я делаю не так?


Ответы (0 шт):