Skip to content

Commit

Permalink
Merge pull request #4 from jumaBrian/main
Browse files Browse the repository at this point in the history
Business Logic implimentation
  • Loading branch information
brienjuma authored Mar 22, 2022
2 parents 94a3679 + c636120 commit 6218f58
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 39 deletions.
80 changes: 41 additions & 39 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h1>NAIROBI'S <span class="text-warning">NO.1 PIZZERIA</span></h1>
customers coming back time after time. Serving crowds of all
ages.
</p>
<button class="btn btn-warning btn-lg">Make Order</button>
<a href="#order"><button class="btn btn-warning btn-lg">Make Order</button></a>
<button class="btn btn-light btn-lg my-2">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down Expand Up @@ -218,7 +218,7 @@ <h1>NAIROBI'S <span class="text-warning">NO.1 PIZZERIA</span></h1>
</select>
</div>
</div>
<button type="submit" class="btn btn-warning my-5">Click to select your choices</button>
<a href="#order-details"><button type="submit" class="btn btn-warning my-5">Click to select your choices</button></a>
<br>
<br>
<br>
Expand All @@ -241,52 +241,54 @@ <h1>NAIROBI'S <span class="text-warning">NO.1 PIZZERIA</span></h1>
</thead>
<tbody id="PizzaDisplay"></tbody>
</table>
<button type="submit" id="target" class="btn btn-warning">PROCEED</button>
<a href="#checkout"><button type="submit" id="target" class="btn btn-warning">PROCEED</button></a>
</div>
</div>
<!-- Order confirmation-->

<div class="row">
<div id="checkout" class="col-md-4 order-md-2 mb-4 select">
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted">Oder id : <span id="track"></span> </span>
</h4>
<div class="list-group mb-3">
<div class="col list-group-item d-flex justify-content-between lh-condensed">Your total Amount is <span id="total"></span> </div>
<div id="wouldYou">
<div class="col list-group-item d-flex justify-content-between lh-condensed">
<p>Would you like a delivery?</p>
<br>
<br>
<div class="list-group-item d-flex justify-content-between lh-condensed">
<button type="submit" id="delivery" class="btn btn-success spice">Yes</button>
<div class="p-5 align-items-lg-center">
<div class="row">
<div id="checkout" class="col-md-4 order-md-2 mb-4 select">
<h4 class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted">Oder id : <span id="track"></span> </span>
</h4>
<div class="list-group mb-3">
<div class="col list-group-item d-flex justify-content-between lh-condensed">Your total Amount is <span id="total"></span> </div>
<div id="wouldYou">
<div class="col list-group-item d-flex justify-content-between lh-condensed">
<p>Would you like a delivery?</p>
<br>
<br>
<div class="list-group-item d-flex justify-content-between lh-condensed">
<button type="submit" id="delivery" class="btn btn-success spice">Yes</button>
<br>
<button type="submit" id="nodeli" class="btn btn-danger spice">No</button>
</div>
</div>
</div>
<!-- Delivery Confirmation-->
<div id="stayLocation" class="col list-group-item">
<div class="col">
<p>You will incur an extra cost of 200 Ksh.</p>
</div>
<label id="stay-text" for="stay">Where do you stay?</label>
<br>
<button type="submit" id="nodeli" class="btn btn-danger spice">No</button>
<input type="text" name="stay" id="stay">
<input type="button" id="withLoc" class="btn btn-warning check" value="Submit Location">
</div>
</div>
</div>
<!-- Delivery Confirmation-->
<div id="stayLocation" class="col list-group-item">
<div class="col">
<p>You will incur an extra cost of 200 Ksh.</p>
</div>
<label id="stay-text" for="stay">Where do you stay?</label>
<div id="final" class="check">
<button type="submit" id="confirm" class="btn btn-success">Confirm Order</button>
<input type="button" onclick="reset()" value="Cancel Order" id="cansel" class="btn btn-danger">
</div>
<div id="message" class="col btn-warning">
<br>
<input type="text" name="stay" id="stay">
<input type="button" id="withLoc" class="btn btn-warning check" value="Submit Location">
<p> Thank you for shopping with us ! Enjoy our Pizza.</p>
<input type="button" class="btn btn-danger check" onclick="reset()" value="X">
<p id="delly"></p>
</div>
</div>
<div id="final" class="check">
<button type="submit" id="confirm" class="btn btn-success">Confirm Order</button>
<input type="button" onclick="reset()" value="Cancel Order" id="cansel" class="btn btn-danger">
</div>
<div id="message" class="col btn-warning">
<br>
<p> Thank you for shopping with us ! Enjoy our Pizza.</p>
<input type="button" class="btn btn-danger check" onclick="reset()" value="X">
<p id="delly"></p>
</div>
</div>
</div>
</div>


</section>
Expand Down
159 changes: 159 additions & 0 deletions js/main.js
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();
});
});

0 comments on commit 6218f58

Please sign in to comment.