Lulunga

DOM 05. Order the Names

Oct 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     document.querySelector('#exercise button').addEventListener('click', () => {
  3.         const name = document.querySelector('#exercise input');
  4.         const list = document.querySelectorAll('ol li');
  5.         const char = name.value
  6.             .toUpperCase()[0];
  7.         const index = char
  8.             .charCodeAt() - 65;
  9.         const formatedName = char + name.value.substr(1).toLowerCase();
  10.         list[index].innerHTML
  11.             ? list[index].innerHTML += ', ' + formatedName
  12.             : list[index].innerHTML = formatedName;
  13.         name.value = '';
  14.     });
  15. }
Add Comment
Please, Sign In to add comment