Pizza Cost Calculator
This calculator helps you determine the cost per square inch of your pizza, allowing you to compare different pizza sizes and toppings effectively. Understanding the true cost per unit of pizza can help you make smarter ordering decisions and appreciate the value you're getting.
Pizza 1 Diameter (inches):
Pizza 1 Cost ($):
Pizza 2 Diameter (inches):
Pizza 2 Cost ($):
Compare Pizza Costs
.calculator-container {
font-family: Arial, sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.input-section {
margin-bottom: 15px;
display: flex;
flex-direction: column;
gap: 10px;
}
.input-section label {
font-weight: bold;
color: #555;
}
.input-section input[type="number"] {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
width: calc(100% – 22px); /* Adjust for padding and border */
}
.calculator-container button {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
width: 100%;
margin-top: 15px;
}
.calculator-container button:hover {
background-color: #45a049;
}
#result {
margin-top: 25px;
padding: 15px;
border: 1px dashed #ccc;
border-radius: 4px;
background-color: #fff;
text-align: center;
font-size: 1.1em;
color: #333;
}
#result p {
margin: 5px 0;
}
function calculatePizzaCost() {
var diameter1 = parseFloat(document.getElementById("diameter1").value);
var cost1 = parseFloat(document.getElementById("cost1").value);
var diameter2 = parseFloat(document.getElementById("diameter2").value);
var cost2 = parseFloat(document.getElementById("cost2").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(diameter1) || isNaN(cost1) || isNaN(diameter2) || isNaN(cost2) || diameter1 <= 0 || cost1 < 0 || diameter2 <= 0 || cost2 < 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Calculate area using the formula: Area = π * (radius)^2 = π * (diameter/2)^2
var radius1 = diameter1 / 2;
var area1 = Math.PI * radius1 * radius1;
var radius2 = diameter2 / 2;
var area2 = Math.PI * radius2 * radius2;
// Calculate cost per square inch
var costPerSqInch1 = cost1 / area1;
var costPerSqInch2 = cost2 / area2;
var message = "";
message += "
Pizza 1: ";
message += "Diameter: " + diameter1.toFixed(1) + " inches";
message += "Area: " + area1.toFixed(2) + " sq. inches";
message += "Cost: $" + cost1.toFixed(2) + "";
message += "
Cost per square inch: $" + costPerSqInch1.toFixed(3) + " ";
message += "
";
message += "
Pizza 2: ";
message += "Diameter: " + diameter2.toFixed(1) + " inches";
message += "Area: " + area2.toFixed(2) + " sq. inches";
message += "Cost: $" + cost2.toFixed(2) + "";
message += "
Cost per square inch: $" + costPerSqInch2.toFixed(3) + " ";
message += "
";
if (costPerSqInch1 < costPerSqInch2) {
message += "Pizza 1 offers better value per square inch.";
} else if (costPerSqInch2 < costPerSqInch1) {
message += "Pizza 2 offers better value per square inch.";
} else {
message += "Both pizzas offer the same value per square inch.";
}
resultDiv.innerHTML = message;
}