// Object to store country population data
const countryPopulations = {
'United States': 329500000,
'China': 1439324000,
'India': 1380004000,
'Indonesia': 273523600,
'Pakistan': 220892000,
'Brazil': 212559000,
'Nigeria': 206139600,
'Bangladesh': 164689800,
'Russia': 145934500,
'Mexico': 126014000,
// Add more countries as needed
};
// Function to get the population of a country
function getCountryPopulation(country) {
const countryName = country.toLowerCase();
if (countryPopulations.hasOwnProperty(countryName)) {
return `The population of ${country} is ${countryPopulations[countryName].toLocaleString()}.`;
} else {
return `Sorry, the population data for ${country} is not available.`;
}
}
// Example usage
console.log(getCountryPopulation('United States')); // Output: The population of United States is 329,500,000.
console.log(getCountryPopulation('France')); // Output: Sorry, the population data for France is not available.
Note that this code assumes you have a finite set of countries and their population data stored in the countryPopulations object. If you need to fetch population data dynamically from an external source, you'll need to modify the code accordingly (e.g., using an API or reading data from a file).