What am I doing wrong here? I am attempting to generate a new array of populations into percentages

//*** Arrays

const populations = [365000000, 7000000, 145000000, 81000000];

// if (populations.length === 4) {

//     console.log(true)

// } else {

//     console.log(false)

// }

const percentageOfWorld = (...populations) => {

    for (let element of populations) {

        return element / 7900000000 * 100;

    }

}

const percentages = percentageOfWorld(...populations);

console.log(percentages.toFixed(2))

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi and welcome.

Can you give us more context? What isn’t working? What happens? What should happen instead? Can you explain what you think the code should be doing?

The more you say, the more we can help.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.