<commit_before>console.log('Script Loaded');

document.addEventListener('DOMContentLoaded', function () {
  const elements = {
    deleteButton: document.querySelector('#delete-button'),
    addAuthorButton: document.querySelector('#add-author-input'),
    addGenreButton: document.querySelector('#add-genre-input'),
    removeInputButton: function () {
      return document.querySelectorAll('.remove-input');
    },
    genreInputs: function () {
      return document.querySelectorAll('.genre-input');
    },
    authorInputs: function () {
      return document.querySelectorAll('.author-input');
    },
    openCart: document.querySelector('.open-cart'),
    modalOverlay: document.querySelector('.modal-overlay'),
    modal: document.querySelector('.modal'),
    closeCart: document.querySelector('.close-cart'),
    cartTotal: document.querySelector('.total'),
    cartContents: document.querySelector('.cart-contents'),
    addToCart: document.querySelector('#add-to-cart-button'),
    bookTitle: document.querySelector('#single-book-title'),
    bookPrice: document.querySelector('#single-book-price'),
    bookISBN: document.querySelector('#single-book-isbn'),
    bookCount: function () {
      return document.querySelectorAll('.book-count');
    },
    inStock: document.querySelector('#single-book-in-stock'),
  };

  const numberInCart = function () {
    return parseInt(elements.openCart.innerText.match(/\d+/));
  };

  const calculateOpenCartTotal = function (arrayOfElements) {
    arrayOfElements.forEach(function (element) {
      element.addEventListener('blur', function () {
        let bookTotalCount = 0;
        let totalPrice = 0;
        arrayOfElements.forEach(function (element) {
          let bookPrice = parseFloat(element.nextElementSibling.innerText.replace(/\$/g, ''));
          let currentBookCount = parseFloat(element.value);
          bookTotalCount += currentBookCount;
          let bookValue = parseFloat((bookPrice * currentBookCount)).toFixed(2);
          totalPrice += parseFloat(bookValue);
        });

        elements.openCart.innerText = `Cart (${bookTotalCount})`;
        elements.cartTotal.innerText = `Total: $${totalPrice.toFixed(2)}`;
      });
    });
  };

  if (elements.bookCount().length > 0) {
    calculateOpenCartTotal(elements.bookCount());<commit_msg>Fixed bug where user could put a negative number as the number of books they wanted to purchase<commit_after>console.log('Script Loaded');

document.addEventListener('DOMContentLoaded', function () {
  const elements = {
    deleteButton: document.querySelector('#delete-button'),
    addAuthorButton: document.querySelector('#add-author-input'),
    addGenreButton: document.querySelector('#add-genre-input'),
    removeInputButton: function () {
      return document.querySelectorAll('.remove-input');
    },
    genreInputs: function () {
      return document.querySelectorAll('.genre-input');
    },
    authorInputs: function () {
      return document.querySelectorAll('.author-input');
    },
    openCart: document.querySelector('.open-cart'),
    modalOverlay: document.querySelector('.modal-overlay'),
    modal: document.querySelector('.modal'),
    closeCart: document.querySelector('.close-cart'),
    cartTotal: document.querySelector('.total'),
    cartContents: document.querySelector('.cart-contents'),
    addToCart: document.querySelector('#add-to-cart-button'),
    bookTitle: document.querySelector('#single-book-title'),
    bookPrice: document.querySelector('#single-book-price'),
    bookISBN: document.querySelector('#single-book-isbn'),
    bookCount: function () {
      return document.querySelectorAll('.book-count');
    },
    inStock: document.querySelector('#single-book-in-stock'),
  };

  const numberInCart = function () {
    return parseInt(elements.openCart.innerText.match(/\d+/));
  };

  const calculateOpenCartTotal = function (arrayOfElements) {
    arrayOfElements.forEach(function (element) {
      element.addEventListener('blur', function () {
        let bookTotalCount = 0;
        let totalPrice = 0;
        arrayOfElements.forEach(function (element) {
          if (parseFloat(element.value) < 0) {
            element.value = 0;
          }
          let bookPrice = parseFloat(element.nextElementSibling.innerText.replace(/\$/g, ''));
          let currentBookCount = parseFloat(element.value);
          bookTotalCount += currentBookCount;
          let bookValue = parseFloat((bookPrice * currentBookCount)).toFixed(2);
          totalPrice += parseFloat(bookValue);
        });

        elements.openCart.innerText = `Cart (${bookTotalCount})`;
        elements.cartTotal.innerText = `Total: $${totalPrice.toFixed(2)}`;
      });
    });
  };

  if (elements.bookCount().length > 0) {
    calculateOpenCartTotal(elements.bookCount());
{'fraction_non_alphanumeric': 0.14472591362126247, 'fraction_numerical': 0.0024916943521594683, 'mean_word_length': 3.764589515331355, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6369660', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1293, 'n_words': 211}