Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function addProduct() {
- let [productElem, priceElem] = Array.from(document.querySelectorAll('input'));
- let tBodyElem = document.getElementById('product-list');
- let totalPriceElem = document.querySelector('tfoot').lastElementChild.lastElementChild;
- const productName = productElem.value;
- const productPrice = Number(priceElem.value);
- if (productName && productPrice > 0) {
- let trElem = document.createElement('tr');
- trElem.innerHTML = `<td>${productName}</td><td>${productPrice}</td>`;
- tBodyElem.appendChild(trElem);
- totalPriceElem.textContent = Number(totalPriceElem.textContent) + productPrice;
- productElem.value = '';
- priceElem.value = '';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement