From c8446c2c7016a1ab7f27cd71037f4b186e36b898 Mon Sep 17 00:00:00 2001 From: Nikola du Preez Date: Mon, 23 Sep 2019 20:32:29 +0200 Subject: [PATCH] done --- .DS_Store | Bin 0 -> 6148 bytes starter-code/.DS_Store | Bin 0 -> 6148 bytes starter-code/index.html | 10 ++-- starter-code/pizza.js | 110 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 starter-code/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..be44ff455d1013acc518e8bd29df219a1c1f09e0 GIT binary patch literal 6148 zcmeHKUu)Dr5TCuCnxNu66zpSO3O-c1qtYTG#Pj-a4}uuc2bDHyf(@kEa>@0u*OPpW z_8a(7`~-fS`kURo;&B#ysi@3^ncrl0W{3PX>>nah{c+kO>JX6!Wo-E{zYy+cU6Ph- zX#lXlKtIi&-cJghpqGD*r_cu%M&J?Mp^9pX zX#|_WKBRrplu|Y<7V^ISZeB8}j$FNO$x)G4b+`LnwN~0UZr<{IJa@g1(Se>sbzG0D zemr{5Z?EF|AaVX1t&2-PPTuC(WVf^WLYH-%m)Xc9=V^wJ5AX6a)swy+muY3jiEIbg z@pn6G)9L2cla1hUuRGfarrX!st9ezHUp3c6U87fHO*Ee#{;T+E4 zTuIb%G%5>SenQMVf1W2O3KH#T z;iN)~Vub-=V3C0p``Y3Cf9LA^|6-E72?N5wf5m`m528UIpXBz|rH|viHh}IySvan- lc$osnY{iJ>t#}P;1nmJkz|di15iJlo2pAf~2m^nVfgi07a7F+C literal 0 HcmV?d00001 diff --git a/starter-code/.DS_Store b/starter-code/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0a4350082cc22658c92cbdd8f1a84a5469675fa1 GIT binary patch literal 6148 zcmeHK%TB{U3>-rbp&aOuV{ULMQV|~zRYig`KLBk(Pz4HvV zdB@rHtdo(t4*)V;P6t2_Kt@*-4O&dQTZgthxkHpR$19F-ix=FZY?p+G3`g96;M)v{f~XhVTeAQbpk zK-Y(yu2?u$hH2?wldb?nJw_*EtjA^L1od686|^XDlYQW!=X3WNep1-9+6r~CgY|1zzY{3a!yLV-}=pD7@n(Zy)UkMg~B zPizza 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) + }; +});