diff --git a/index.html b/index.html index b450bdb..220d1db 100644 --- a/index.html +++ b/index.html @@ -72,7 +72,7 @@

NAIROBI'S NO.1 PIZZERIA

customers coming back time after time. Serving crowds of all ages.

- + +


@@ -241,52 +241,54 @@

NAIROBI'S NO.1 PIZZERIA

- + -
-
-

- Oder id : -

-
-
Your total Amount is
-
-
-

Would you like a delivery?

-
-
-
- +
+
+
+

+ Oder id : +

+
+
Your total Amount is
+
+
+

Would you like a delivery?

+
+
+
+ +
+ +
+
+
+ +
+
+

You will incur an extra cost of 200 Ksh.

+
+
- + +
-
- -
-
-

You will incur an extra cost of 200 Ksh.

-
- +
+ + +
+

- - +

Thank you for shopping with us ! Enjoy our Pizza.

+ +

-
-
- - -
-
-
-

Thank you for shopping with us ! Enjoy our Pizza.

- -

-
-
+
+
diff --git a/js/main.js b/js/main.js index e69de29..e0aac41 100644 --- a/js/main.js +++ b/js/main.js @@ -0,0 +1,159 @@ +// Business Logic - information/data itself/functions expected + +function Pizza(size, crust, topping) { + this.size = size; + this.crust = crust; + this.topping = topping; + this.total = + parseInt(this.size) + parseInt(this.crust) + parseInt(this.topping); +} +function PizzaOrder() { + this.pizza = []; +} + +function resetFields() { + var inputtedSizePrice = $("#pizzaSize").val(""); + var inputtedCrustPrice = $("#pizzacrust").val(""); + var inputtedToppingPrice = $("#pizzaToppings").val(""); +} + +function genRandId() { + var rand = Math.floor(Math.random() * 77); + return `#PIZZ${rand}-D`; +} +function genOderId() { + var rand = Math.floor(Math.random() * 88); + return `#PZODR${rand}-D`; +} +var reset = function () { + location.reload(); +}; + +Pizza.prototype.getSize = function (size) { + if (size === "600") { + return `Small - ${this.size}`; + } else if (size === "900") { + return `Medium - ${this.size}`; + } else if (size === "1200") { + return `Large - ${this.size}`; + } +}; + +Pizza.prototype.getCrust = function (crust) { + if (crust === "150") { + return `Cripsy - ${this.crust}`; + } else if (crust === "175") { + return `Stuffed - ${this.crust}`; + } else if (crust === "200") { + return `Gluten Free - ${this.crust}`; + } +}; + +Pizza.prototype.getToppings = function (topping) { + if (topping === "225") { + return `Pepperoni - ${this.topping}`; + } else if (topping === "245") { + return `Mushrooms - ${this.topping}`; + } else if (topping === "265") { + return `Gorgonzola - ${this.topping}`; + } +}; + +Pizza.prototype.getTotal = function () { + return this.total; +}; + +var deliveryOrder = new PizzaOrder(); +var sum = 0; + +function getGrandTotal() { + for (let i = 0; i < deliveryOrder.pizza.length; i++) { + sum += deliveryOrder.pizza[i].total; + } + return sum; +} + +//Application Logic - how it happens. + +$(document).ready(function () { + $("#order-details").hide(); + $("#checkout").hide(); + $("#stayLocation").hide(); + $("#message").hide(); + $("form#order").submit(function (event) { + event.preventDefault(); + var inputtedSizePrice = $("#pizzaSize").val(); + var inputtedCrustPrice = $("#pizzacrust").val(); + var inputtedToppingPrice = $("#pizzaToppings").val(); + if ( + inputtedSizePrice === "" || + inputtedCrustPrice === "" || + inputtedToppingPrice === "" + ) { + reset(); + alert("Please make a pick from the available options"); + } else { + var pickedPizza = new Pizza( + inputtedSizePrice, + inputtedCrustPrice, + inputtedToppingPrice + ); + var placedOrder = new PizzaOrder(); + placedOrder.pizza.push(pickedPizza); + deliveryOrder.pizza.push(pickedPizza); + resetFields(); + } + + $("#order-details").show(); + placedOrder.pizza.forEach(function (pickedPizza) { + $("#PizzaDisplay").append(` + ${genRandId()} + ${pickedPizza.getSize(pickedPizza.size)} + ${pickedPizza.getCrust(pickedPizza.crust)} + ${pickedPizza.getToppings(pickedPizza.topping)} + ${pickedPizza.getTotal()} + `); + }); + }); + + $("#target").click(function () { + $("#checkout").show(); + $("#message").hide(); + $("#target").hide(); + $("#stayLocation").hide(); + $("#track").append(`${genOderId()}`); + $("#total").append(`${getGrandTotal()}`); + }); + + $("#delivery").click(function () { + $("#stayLocation").show(); + $("#wouldYou").hide(); + }); + + $("#withLoc").click(function () { + var location = $("#stay").val(); + if (location === "") { + alert("Enter delivery location"); + } else { + $("#withLoc").hide(); + $("#stay-text").hide(); + $("#stay").hide(); + $("#delly") + .append(`Your grand total, inclusive of delivery fee is ${ + sum + 200 + } + Your order will be delivered to + ${location}`); + } + }); + + $("#nodeli").click(function () { + $("#wouldYou").hide(); + }); + + $("#confirm").click(function () { + $("#final").hide(); + $("#stayLocation").hide(); + $("#message").show(); + }); +});