bobo_bobkata

Untitled

Oct 9th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. function solve() {
  2. const textArea = document.querySelector('textarea');
  3. let total = 0;
  4. const products = new Set();
  5. let isCheckout = false ;
  6. document.querySelector('.checkout').addEventListener('click', () => {
  7. if (isCheckout){
  8. return;
  9. }
  10. textArea.value += `You bought ${[ ...products ].join(', ')} for ${total.toFixed(2)}.`;
  11. isCheckout = true;
  12. });
  13. [ ...document.querySelectorAll('.add-product') ].forEach(e => e.addEventListener('click', (ev) => {
  14. if (isCheckout){
  15. return;
  16. }
  17. const price = ev.target.parentElement.parentElement.querySelector('.product-line-price').innerHTML;
  18. const product = ev.target.parentElement.parentElement.querySelector('.product-title').innerHTML;
  19. textArea.value += `Added ${product} for ${price} to the cart.\n`;
  20. total += Number(price);
  21. products.add(product);
  22. }));
  23. }
Add Comment
Please, Sign In to add comment