Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Gabriel Wilk
Gabriel Wilk
193 Points

Hi, how would I have the scorebord App display the players based on score? For example, having high score first etc etc

Just wondering how to implement functionality where player display is organized by their score. If this is already covered in this course, please let me know where! Thanks you!

1 Answer

I don't know how the data is structured in your case, but an example would be using the array sort method.

Assuming the data is stored in an array of objects like this:

const players = [{name: 'Alice', score: 8, id: 1}, {name: 'Bob', score: 5, id: 2}]
const sortedPlayers = players.sort((player1, player2) => player1.score - player2.score)