Currently diving into the world of JavaScript and embarking on a journey with Stack Overflow (enrolled in a JavaScript Udemy course as well). During an exercise involving arrays, I found that the Chrome Dev console was only displaying [f, f, f, f] along with the entire percentages array instead of the values I anticipated. Take a look at my code:
//function to calculate percentage of world population
function percentageOfWorld1(population) {
return ((population / 7900) * 100);
}
//array consisting of various populations (in millions)
const populations = [331.9, 1458, 1380, 147.2];
//checking if there are 4 elements in the array
console.log(populations.length === 4);
//converting each element in the array to percentage using the function
const percentages = [
percentageOfWorld1(populations[0]),
percentageOfWorld1(populations[1]),
percentageOfWorld1(populations[2]),
percentageOfWorld1(populations[3])
];
//displaying the resulting array
console.log(percentages);
This is what I see in the Chrome Dev console: Screenshot
I'm puzzled by the fact that it's showing [f, f, f, f] rather than numbers in an array.
I tried looking for solutions but couldn't find anything helpful. Even tweaking the variables didn't alter the output in the console. However, the console.log verifying the presence of 4 array elements yielded the expected result.