Advertisement
Todorov_Stanimir

01. Coffee Bill JS Advanced Retake - 18 April 2019

Oct 23rd, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  function addProduct() {
  2.             let [productElem, priceElem] = Array.from(document.querySelectorAll('input'));
  3.             let tBodyElem = document.getElementById('product-list');
  4.             let totalPriceElem = document.querySelector('tfoot').lastElementChild.lastElementChild;
  5.             const productName = productElem.value;
  6.             const productPrice = Number(priceElem.value);
  7.             if (productName && productPrice > 0) {
  8.                 let trElem = document.createElement('tr');
  9.                 trElem.innerHTML = `<td>${productName}</td><td>${productPrice}</td>`;
  10.                 tBodyElem.appendChild(trElem);
  11.                 totalPriceElem.textContent = Number(totalPriceElem.textContent) + productPrice;
  12.                 productElem.value = '';
  13.                 priceElem.value = '';
  14.             }
  15.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement