Uber Fare Calculator
This calculator helps you estimate your Uber fare based on common pricing factors. Keep in mind that actual fares can vary due to real-time demand, surge pricing, and specific city regulations.
Distance (km):
Duration (minutes):
Base Fare ($):
Cost Per Km ($):
Cost Per Minute ($):
Booking Fee ($):
Surge Multiplier (e.g., 1.0 for no surge, 1.5 for 50% surge):
Calculate Fare
function calculateUberFare() {
var distance = parseFloat(document.getElementById("distance").value);
var time = parseFloat(document.getElementById("time").value);
var baseFare = parseFloat(document.getElementById("baseFare").value);
var costPerKm = parseFloat(document.getElementById("costPerKm").value);
var costPerMin = parseFloat(document.getElementById("costPerMin").value);
var bookingFee = parseFloat(document.getElementById("bookingFee").value);
var surgeMultiplier = parseFloat(document.getElementById("surgeMultiplier").value);
var resultElement = document.getElementById("result");
if (isNaN(distance) || isNaN(time) || isNaN(baseFare) || isNaN(costPerKm) || isNaN(costPerMin) || isNaN(bookingFee) || isNaN(surgeMultiplier)) {
resultElement.innerHTML = "Please enter valid numbers for all fields.";
return;
}
if (distance < 0 || time < 0 || baseFare < 0 || costPerKm < 0 || costPerMin < 0 || bookingFee < 0 || surgeMultiplier < 0) {
resultElement.innerHTML = "Values cannot be negative.";
return;
}
// Calculation logic
// Fare = (Base Fare + (Distance * Cost Per Km) + (Duration * Cost Per Minute)) * Surge Multiplier + Booking Fee
var estimatedFare = (baseFare + (distance * costPerKm) + (time * costPerMin)) * surgeMultiplier + bookingFee;
// Display the result, formatted to two decimal places
resultElement.innerHTML = "Estimated Uber Fare: $" + estimatedFare.toFixed(2);
}
.uber-calculator {
font-family: sans-serif;
max-width: 500px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
}
.uber-calculator h2 {
text-align: center;
margin-bottom: 20px;
color: #000;
}
.uber-calculator p {
font-size: 0.9em;
color: #555;
margin-bottom: 20px;
}
.input-section {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.input-section label {
margin-bottom: 5px;
font-weight: bold;
color: #333;
}
.input-section input[type="number"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
}
.uber-calculator button {
width: 100%;
padding: 12px 15px;
background-color: #000;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
}
.uber-calculator button:hover {
background-color: #333;
}
#result {
margin-top: 20px;
padding: 15px;
background-color: #eef;
border: 1px solid #ddf;
border-radius: 4px;
text-align: center;
font-size: 1.2em;
font-weight: bold;
color: #000;
}