Skip to content
Advertisement

Function returns Nan returns when I send More argument then function parameters

I couldn’t understand why it send the nan when I pass more arguments than parameters

function percetageofworld3(population1) {
    return (population1 / 7900) * 100;
}
const describePopulation = function(country, population) {
    const chinesePopulation = percetageofworld3(country, population);
    console.log(chinesePopulation)
    const countries = `${country} has ${population} million people,
        which is about ${chinesePopulation}% of the world`
    return countries;
}

Advertisement

Answer

You pass into percetageofworld3 two parameter but the function have just one, so you pass country for example ‘italy’ and it will be return ('italy' / 7900) * 100;

If you pass only number work

function percetageofworld3(population1) {
  return (population1 / 7900) * 100;
}
const describePopulation = function(country, population) {
  const chinesePopulation = percetageofworld3(population);
  console.log('Result of chinesePopulation: ' + chinesePopulation)
  const countries = `${country} has ${population} million people,
which is about ${chinesePopulation}% of the world`
  return countries;
}
console.log('Result of describePopulation: ' + describePopulation('italy', 1000))
Advertisement