SHARE
TWEET

04. Order the Names

Todorov_Stanimir Jun 2nd, 2020 846 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     document.getElementsByTagName('button')[0].onclick = function exe () {
  4.         let name = document.getElementsByTagName('input')[0];
  5.         //alert(name.value);
  6.    
  7.         const modifiedName = name.value.split('').map((el, ind) => ind === 0 ? el.toUpperCase() : el.toLowerCase()).join('');
  8.         const i = modifiedName.charCodeAt(0) //instead let i = (name.value).charCodeAt(0);
  9.         //alert(i);
  10.            
  11.         let a = document.getElementsByTagName('li')[i - 65];
  12.         //alert(a.innerHTML);
  13.                
  14.         if (a.innerText === '') {
  15.             a.innerHTML = modifiedName; //instead  a.innerHTML = name.value;
  16.         } else {
  17.             a.innerHTML = a.innerHTML + ', ' + modifiedName; //instead a.innerHTML = a.innerHTML + ', ' + name.value;
  18.         }
  19.                    
  20.         name.value = '';
  21.        
  22.     }
  23.    
  24. }
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