diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..be44ff45 Binary files /dev/null and b/.DS_Store differ diff --git a/starter-code/.DS_Store b/starter-code/.DS_Store new file mode 100644 index 00000000..0a435008 Binary files /dev/null and b/starter-code/.DS_Store differ diff --git a/starter-code/index.html b/starter-code/index.html index 189a3311..fe271d56 100755 --- a/starter-code/index.html +++ b/starter-code/index.html @@ -26,10 +26,10 @@

Pizza Builder

  • - +
  • - +
  • @@ -44,10 +44,10 @@

    Your pizza's price

  • $1 pepperonni
  • $1 mushrooms
  • $1 green peppers
  • -
  • $3 white sauce
  • -
  • $5 gluten-free crust
  • +
  • $3 white sauce
  • +
  • $5 gluten-free crust
  • - $21 + $13 diff --git a/starter-code/pizza.js b/starter-code/pizza.js index b473d048..e0103af6 100755 --- a/starter-code/pizza.js +++ b/starter-code/pizza.js @@ -1 +1,109 @@ -// Write your Pizza Builder JavaScript in this file. +let totalPrice = 13; + +function updateTotalPrice(toppingPrice) { + totalPrice += toppingPrice; + $('.price strong').html('$' + totalPrice); +}; + +function toppingButtonClicked(button, displayItem, listItem, toppingPrice){ + listItem.toggle(); + displayItem.toggle(); + + if (listItem.is(':visible') && !button.hasClass('active')){ + button.addClass('active'); + updateTotalPrice(toppingPrice); + } else { + button.removeClass('active'); + updateTotalPrice(-toppingPrice); + }; +}; + +function toppingRemove(button, displayItem, listItem, toppingPrice){ + listItem.hide(); + displayItem.hide(); + + if (listItem.is(':visible') && !button.hasClass('active')){ + button.addClass('active'); + updateTotalPrice(toppingPrice); + } else { + button.removeClass('active'); + updateTotalPrice(-toppingPrice); + }; +}; + +//pepperonni +$('.btn-pepperonni').click(function(){ + toppingButtonClicked($('.btn-pepperonni'), $('.pep'), $('.price li:eq(0)'), 1); +}); + +$('.price li:eq(0)').click(function() { + toppingRemove($('.btn-pepperonni'), $('.pep'), $('.price li:eq(0)'), 1); +}); + +//mushrooms +$('.btn-mushrooms').click(function(){ + toppingButtonClicked($('.btn-mushrooms'), $('.mushroom'), $('.price li:eq(1)'), 1); +}); + +$('.price li:eq(1)').click(function() { + toppingRemove($('.btn-mushrooms'), $('.mushroom'), $('.price li:eq(1)'), 1); +}); + +//green-peppers +$('.btn-green-peppers').click(function(){ + toppingButtonClicked($('.btn-green-peppers'), $('.green-pepper'), $('.price li:eq(2)'), 1); +}); + +$('.price li:eq(2)').click(function() { + toppingRemove($('.btn-green-peppers'), $('.green-pepper'), $('.price li:eq(2)'), 1); +}); + +//sauce +$('.btn-sauce').click(function() { + $(`.price li:contains("$3 white sauce")`).toggle(); + + if ($(`.price li:contains("$3 white sauce"):visible`) && !$('.btn-sauce').hasClass('active')){ + $(this).addClass('active'); + updateTotalPrice(3) + } else { + $(this).removeClass('active'); + updateTotalPrice(-3) + }; +}); + +$(`.price li:contains("$3 white sauce")`).click(function(){ + $(this).hide(); + + if ($(`.price li:contains("$3 white sauce"):visible`) && !$('.btn-sauce').hasClass('active')){ + $(this).addClass('active'); + updateTotalPrice(3) + } else { + $(this).removeClass('active'); + updateTotalPrice(-3) + }; +}); + +//crust +$('.btn-crust').click(function() { + $(`.price li:contains("$5 gluten-free crust")`).toggle(); + + if ($(`.price li:contains("$5 gluten-free crust"):visible`) && !$('.btn-crust').hasClass('active')){ + $(this).addClass('active'); + updateTotalPrice(5) + } else { + $(this).removeClass('active'); + updateTotalPrice(-5) + }; +}); + +$(`.price li:contains("$5 gluten-free crust")`).click(function(){ + $(this).hide(); + + if ($(`.price li:contains("$5 gluten-free crust"):visible`) && !$('.btn-crust').hasClass('active')){ + $(this).addClass('active'); + updateTotalPrice(5) + } else { + $(this).removeClass('active'); + updateTotalPrice(-5) + }; +});