From 1c0a49d1fb039942d1f07539ea62e2f6be518e05 Mon Sep 17 00:00:00 2001 From: Debasri Dasgupta Date: Sat, 16 Feb 2019 10:16:10 +0100 Subject: [PATCH 1/2] pizza is flying --- starter-code/index.html | 12 ++++----- starter-code/pizza.js | 56 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/starter-code/index.html b/starter-code/index.html index 189a3311..e58adbd7 100755 --- a/starter-code/index.html +++ b/starter-code/index.html @@ -17,13 +17,13 @@

Pizza Builder

$21 @@ -268,9 +268,9 @@

Your pizza's price

31
33
-
+
-
+
diff --git a/starter-code/pizza.js b/starter-code/pizza.js index b473d048..c914a9de 100755 --- a/starter-code/pizza.js +++ b/starter-code/pizza.js @@ -1 +1,57 @@ // Write your Pizza Builder JavaScript in this file. + $('.btn-pepperonni').click(function() { + $('.pep').toggle(function(){ + if($('.btn-pepperonni').hasClass("active")) { + $('.price li').eq(0).hide(); + } + else{ + $('.price li').eq(0).show(); + } + }); + }) + + $('.btn-mushrooms').click(function() { + $('.mushroom').toggle(function(){ + if($('.btn-mushrooms').hasClass("active")) { + $('.price li').eq(1).hide(); + } + else{ + $('.price li').eq(1).show(); + } + }); + }) + + $('.btn-green-peppers').click(function() { + $('.green-pepper').toggle( function(){ + if($('.btn-green-peppers').hasClass("active")) { + $('.price li').eq(2).hide(); + } + else{ + $('.price li').eq(2).show(); + } + }); + }) + + $('.btn-sauce').click(function() { + $('.sauce').toggleClass("sauce-white") + if($('.btn-sauce').hasClass("active")) { + console.log("active"); + $('.price li').eq(3).show(); + } + else{ + $('.price li').eq(3).hide(); + } + }) + $('.btn-sauce').click(function(){ + + console.log('button clicked'); + }) + $('.btn-crust').click(function() { + $('.crust-gluten-free').toggleClass("crust"); + }) + + $(".btn").click(function(){ + $(this).toggleClass("active"); + }) + + From 3611185667c346499300c8f74162bae49fa615c7 Mon Sep 17 00:00:00 2001 From: Debasri Dasgupta Date: Mon, 18 Feb 2019 01:34:02 +0100 Subject: [PATCH 2/2] Pizza Project done --- starter-code/index.html | 12 +-- starter-code/pizza.js | 177 ++++++++++++++++++++++++++++------------ 2 files changed, 132 insertions(+), 57 deletions(-) diff --git a/starter-code/index.html b/starter-code/index.html index e58adbd7..59a72c24 100755 --- a/starter-code/index.html +++ b/starter-code/index.html @@ -41,13 +41,13 @@

Your pizza's price

$10 cheese pizza - $21 + $ diff --git a/starter-code/pizza.js b/starter-code/pizza.js index c914a9de..d12f8934 100755 --- a/starter-code/pizza.js +++ b/starter-code/pizza.js @@ -1,57 +1,132 @@ // Write your Pizza Builder JavaScript in this file. - $('.btn-pepperonni').click(function() { - $('.pep').toggle(function(){ - if($('.btn-pepperonni').hasClass("active")) { - $('.price li').eq(0).hide(); - } - else{ +$('document').ready(function () { + + // array to calc final pizza price + var pizzaTotalPrice = [{ type: '', price: 0 }]; + + // create object containing base pizza price + + pizzaTotalPrice.push({ + type: "basePizza", + price: 10 + }); + + pizzaTotalPrice.push({ + type: "pepperonniTopping", + price: 1 + }); + + pizzaTotalPrice.push({ + type: "mushroomTopping", + price: 1 + }); + + pizzaTotalPrice.push({ + type: "greenPepperTopping", + price: 1 + }); + + // Total value Calculation + + var pizzaTotal = pizzaTotalPrice.reduce((a, b) => ({ price: a.price + b.price })); + $("#total").text("$" + pizzaTotal.price); + + // Pepperoni topping button + + $('.btn-pepperonni').click(function () { + $('.pep').toggle() + if ($('.btn-pepperonni').hasClass("active")) { $('.price li').eq(0).show(); + + pizzaTotalPrice.push({ + type: "pepperonniTopping", + price: 1 + }) + + } + else { + $('.price li').eq(0).hide(); + pizzaTotalPrice.splice(pizzaTotalPrice.map(function (e) { return e.type; }).indexOf('pepperonniTopping'), 1); } - }); - }) + }); + + // Mushroom topping button - $('.btn-mushrooms').click(function() { - $('.mushroom').toggle(function(){ - if($('.btn-mushrooms').hasClass("active")) { + $('.btn-mushrooms').click(function () { + $('.mushroom').toggle() + if ($('.btn-mushrooms').hasClass("active")) { + $('.price li').eq(1).show(); + + pizzaTotalPrice.push({ + type: "mushroomTopping", + price: 1 + }) + } + else { $('.price li').eq(1).hide(); + pizzaTotalPrice.splice(pizzaTotalPrice.map(function (e) { return e.type; }).indexOf('mushroomTopping'), 1); } - else{ - $('.price li').eq(1).show(); - } - }); - }) - - $('.btn-green-peppers').click(function() { - $('.green-pepper').toggle( function(){ - if($('.btn-green-peppers').hasClass("active")) { - $('.price li').eq(2).hide(); - } - else{ - $('.price li').eq(2).show(); - } - }); - }) - - $('.btn-sauce').click(function() { - $('.sauce').toggleClass("sauce-white") - if($('.btn-sauce').hasClass("active")) { - console.log("active"); - $('.price li').eq(3).show(); - } - else{ - $('.price li').eq(3).hide(); - } - }) - $('.btn-sauce').click(function(){ - - console.log('button clicked'); - }) - $('.btn-crust').click(function() { - $('.crust-gluten-free').toggleClass("crust"); - }) - - $(".btn").click(function(){ - $(this).toggleClass("active"); - }) - - + }); + + // Green Pepper topping button + + $('.btn-green-peppers').click(function () { + $('.green-pepper').toggle() + if ($('.btn-green-peppers').hasClass("active")) { + $('.price li').eq(2).show(); + pizzaTotalPrice.push({ + type: "greenPepperTopping", + price: 1 + }) + } + else { + $('.price li').eq(2).hide(); + pizzaTotalPrice.splice(pizzaTotalPrice.map(function (e) { return e.type; }).indexOf('greenPepperTopping'), 1); + } + }); + + // White Sauce topping button + + $('.btn-sauce').click(function () { + $('.sauce').toggleClass("sauce-white") + if ($('.btn-sauce').hasClass("active")) { + + $('.price li').eq(3).show(); + pizzaTotalPrice.push({ + type: "whiteSauceTopping", + price: 3 + }) + } + else { + $('.price li').eq(3).hide(); + pizzaTotalPrice.splice(pizzaTotalPrice.map(function (e) { return e.type; }).indexOf('whiteSauceTopping'), 1); + } + }); + + // Gluten Free Crust button + $('.btn-crust').click(function () { + $('.crust-gluten-free').toggleClass("crust") + if ($('.btn-crust').hasClass("active")) { + + $('.price li').eq(4).show(); + pizzaTotalPrice.push({ + type: "GlutenFreeCrust", + price: 5 + }) + } + else { + $('.price li').eq(4).hide(); + pizzaTotalPrice.splice(pizzaTotalPrice.map(function (e) { return e.type; }).indexOf('GlutenFreeCrust'), 1); + } + }); + + //Total Price Calculation + + $(".btn").on("click", function () { + $(this).toggleClass("active"); + + var pizzaTotal = pizzaTotalPrice.reduce((a, b) => ({ price: a.price + b.price })); + $("#total").text("$" + pizzaTotal.price); + }); + +});