Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- let input = document.querySelector('input');
- let wholeList = document.querySelectorAll('li');
- function capitalize(text){
- return text.charAt(0).toUpperCase() + text.slice(1);
- }
- let addButton = document.querySelector('button');
- addButton.addEventListener('click', function () {
- let currentName = input.value;
- let position = currentName[0].charCodeAt(0) - 97;
- if (wholeList[position].textContent === ''){
- wholeList[position].textContent = capitalize(currentName);
- }
- else{
- wholeList[position].textContent += `, ${capitalize(currentName)}`;
- }
- console.log(wholeList[position].textContent);
- console.log(position);
- input.value = '';
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement