SHARE
TWEET

Untitled

a guest May 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     let input = document.querySelector('input');
  4.     let wholeList = document.querySelectorAll('li');
  5.  
  6.     function capitalize(text){
  7.         return text.charAt(0).toUpperCase() + text.slice(1);
  8.     }
  9.  
  10.  
  11.     let addButton = document.querySelector('button');
  12.     addButton.addEventListener('click', function () {
  13.         let currentName = input.value;
  14.         let position = currentName[0].charCodeAt(0) - 97;
  15.         if (wholeList[position].textContent === ''){
  16.             wholeList[position].textContent = capitalize(currentName);
  17.         }
  18.         else{
  19.             wholeList[position].textContent += `, ${capitalize(currentName)}`;
  20.         }
  21.         console.log(wholeList[position].textContent);
  22.         console.log(position);
  23.         input.value = '';
  24.     })
  25.  
  26. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top