Food Ranking


jQuery DOM manipulation Public New

Hard 

20min


A website needs a list where users can rank their favorite foods. Write the setup function, which should register click handlers on all Up! and Down! buttons. The Up! button should move the list item one place up in the list, while Down! button should move the list item one place down in the list.

For example, consider this code:

document.body.innerHTML = `<ol>
  <li><button>Up!</button>Taco<button>Down!</button></li>
  <li><button>Up!</button>Pizza<button>Down!</button></li>
  <li><button>Up!</button>Eggs<button>Down!</button></li>
</ol>`;

setup();

If the button Up! button in Pizza list item is clicked, Pizza should be the first item in the list, while Taco should be the second item.

ECMAScript 6, jQuery v3.2.1 (available as $)
   

  •   Example case: Wrong answer
  •   Elements can move up: Wrong answer
  •   Elements can move down: Wrong answer