You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
btnAddItem.addEventListener('click',()=>{constITEM_KEY=inputItem.value.toUpperCase();constITEM_VALUE=inputItem.value;// NOTE: Create elementconstlistItem=document.createElement('li');consttextItem=document.createElement('p');constbtnDelete=document.createElement('button');constcounter=document.createElement('button');// WARN: Handle error, empty inputif(ITEM_VALUE===''){alert("Item Name can't be blank");inputItem.focus();return;}// WARN: Check for duplicationif(database.has(ITEM_KEY)){alert(`You already have ${ITEM_VALUE}`);inputItem.value='';inputItem.focus();return;}// NOTE: Add the new item to databasedatabase.set(ITEM_KEY,ITEM_VALUE);// NOTE: Add attributelistItem.classList.add('list-item');// NOTE: Add Class// NOTE: Add valuetextItem.textContent=ITEM_VALUE;btnDelete.textContent='Delete';// NOTE: The counter should be dynamicly show how much do we have for this itemcounter.textContent=5;// NOTE: Combine elementslistItem.append(textItem,btnDelete,counter);listContainer.appendChild(listItem);// NOTE: Handle click event for delete buttonbtnDelete.addEventListener('click',()=>{listContainer.removeChild(listItem);});inputItem.value='';inputItem.focus();});
TASK
Add delete confirmation
If user confirms yes, delete the item if it is the only item, otherwise decrease the counter
If user confirm no/decline/press ESC, do not delete the item
Item counter
If user input the same item, display a counter showing how many related item do we have
If there are only items, do not display the counter