JenMorgan / js-learning

0 stars 0 forks source link

to extract the value from string #43

Open JenMorgan opened 4 years ago

JenMorgan commented 4 years ago
function extractCurrencyValue (str) {
    for (let i = 0; i < str.length - 1; i++) {
        if (!isNaN(parseInt(str[i]))) return parseInt(str.slice(i));
        }
    return "There is no currency value provided";
}

alert( extractCurrencyValue('the price is 300 USD'))