← Back to HTML DOM
Question 189
Reverse the Order of List Items
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 withArray.from(list.children). 2. Reverse that array. 3. Loop over it andappendChildeach<li>back onto the list.
Expected Output:
<ul id="ranking"> <li>Third</li> <li>Second</li> <li>First</li> </ul>
= newline. No newline after the last line.
Hints4 available
Sign in to use hintsTopics:
HTML DOM
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.