-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jumaBrian/main
Business Logic implimentation
- Loading branch information
Showing
2 changed files
with
200 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(`<tr> | ||
<th scope="row">${genRandId()}</th> | ||
<td>${pickedPizza.getSize(pickedPizza.size)}</td> | ||
<td>${pickedPizza.getCrust(pickedPizza.crust)}</td> | ||
<td>${pickedPizza.getToppings(pickedPizza.topping)}</td> | ||
<td>${pickedPizza.getTotal()}</td> | ||
</tr>`); | ||
}); | ||
}); | ||
|
||
$("#target").click(function () { | ||
$("#checkout").show(); | ||
$("#message").hide(); | ||
$("#target").hide(); | ||
$("#stayLocation").hide(); | ||
$("#track").append(`<strong>${genOderId()}</strong>`); | ||
$("#total").append(`<strong>${getGrandTotal()}</strong>`); | ||
}); | ||
|
||
$("#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 <strong>${ | ||
sum + 200 | ||
}</strong> | ||
Your order will be delivered to | ||
<strong>${location}</strong>`); | ||
} | ||
}); | ||
|
||
$("#nodeli").click(function () { | ||
$("#wouldYou").hide(); | ||
}); | ||
|
||
$("#confirm").click(function () { | ||
$("#final").hide(); | ||
$("#stayLocation").hide(); | ||
$("#message").show(); | ||
}); | ||
}); |