CJCoding With Joseph

Reverse the Order of List Items

Reverse the order of the <li> items inside the list with id="ranking" so the list reads "Third", "Second", "First". Re-appending an existing element MOVES it to the end, so appending the items in reversed order reverses the list.

Platform-Provided HTML (READ-ONLY):
<ul id="ranking">
  <li>First</li>
  <li>Second</li>
  <li>Third</li>
</ul>

Steps:
1. Get the list, then copy its children into a real array with Array.from(list.children).
2. Reverse that array.
3. Loop over it and appendChild each <li> back onto the list.

Expected Output:

<ul id="ranking">
  <li>Third</li>
  <li>Second</li>
  <li>First</li>
</ul>
Topics:
HTML DOM
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (clog, fn, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.