From cc45265256bdf06a7e802fab8ca61a12fbf6c5fc Mon Sep 17 00:00:00 2001 From: Vlada Date: Tue, 16 Jul 2019 17:53:21 +0200 Subject: [PATCH] done --- .vscode/settings.json | 3 +++ starter-code/index.html | 6 ++--- starter-code/pizza.js | 53 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..f673a71b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5502 +} \ No newline at end of file diff --git a/starter-code/index.html b/starter-code/index.html index 189a3311..9f72a7d7 100755 --- a/starter-code/index.html +++ b/starter-code/index.html @@ -47,7 +47,7 @@

Your pizza's price

  • $3 white sauce
  • $5 gluten-free crust
  • - $21 + $13 @@ -268,9 +268,9 @@

    Your pizza's price

    31
    33
    -
    +
    -
    +
    diff --git a/starter-code/pizza.js b/starter-code/pizza.js index b473d048..4daea1f9 100755 --- a/starter-code/pizza.js +++ b/starter-code/pizza.js @@ -1 +1,54 @@ // Write your Pizza Builder JavaScript in this file. +$(document).ready(function(){ + //by default the crust is not gluten-free and the sause is not white + $(".panel.price ul li:nth-child(5)").hide() + $(".panel.price ul li:nth-child(4)").hide() + //by default crust and sause has no active class + $(".btn-crust").toggleClass("active") + $(".btn-sauce").toggleClass("active") + + var total = 13 + $(".btn-green-peppers").click(function(){ + $("#pizza .green-pepper").toggle() + $(".btn-green-peppers").toggleClass("active") + $(".panel.price ul li:nth-child(3)").toggle() + calculateTotal(".btn-green-peppers",1) + }) + $(".btn-mushrooms").click(function(){ + $("#pizza .mushroom").toggle() + $(".btn-mushrooms").toggleClass("active") + $(".panel.price ul li:nth-child(2)").toggle() + calculateTotal(".btn-mushrooms",1) + }) + $(".btn-pepperonni").click(function(){ + $("#pizza .pep").toggle() + $(".btn-pepperonni").toggleClass("active") + $(".panel.price ul li:nth-child(1)").toggle() + calculateTotal(".btn-pepperonni",1) + }) + $(".btn-crust").click(function(){ + $(".crust").toggleClass("crust-gluten-free") + $(".btn-crust").toggleClass("active") + $(".panel.price ul li:nth-child(5)").show() + calculateTotal(".btn-crust",5) + }) + $(".btn-sauce").click(function(){ + $(".sauce").toggleClass("sauce-white") + $(".btn-sauce").toggleClass("active") + $(".panel.price ul li:nth-child(4)").show() + calculateTotal(".btn-sauce",3) + }) + + function calculateTotal (btn,price){ + //debugger + if ($(btn).hasClass("active") === false){ + total = total - price + } else { + total = total + price + } + return $(".panel.price strong").html(`$${total}`) + ///debugger + } + + +})