This calculator helps you estimate the time it will take to complete a hike based on distance, average hiking speed, and elevation gain. It also considers a common rule of thumb for adjusting speed based on uphill climbs.
function calculateHikingTime() {
var distance = parseFloat(document.getElementById("distance").value);
var avgSpeed = parseFloat(document.getElementById("avgSpeed").value);
var elevationGain = parseFloat(document.getElementById("elevationGain").value);
var elevationFactor = parseFloat(document.getElementById("elevationFactor").value);
var restBreaks = parseFloat(document.getElementById("restBreaks").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(distance) || isNaN(avgSpeed) || isNaN(elevationGain) || isNaN(elevationFactor) || isNaN(restBreaks) ||
distance <= 0 || avgSpeed <= 0 || elevationFactor < 0 || restBreaks < 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields. Elevation adjustment and rest breaks can be zero.";
return;
}
// 1. Calculate base hiking time based on distance and speed
var baseHikingTimeHours = distance / avgSpeed;
// 2. Calculate additional time for elevation gain
// Convert elevation gain to hundreds of meters for the factor
var elevationTimeHours = (elevationGain / 100) * (elevationFactor / 60); // Convert minutes to hours
// 3. Calculate total active hiking time
var totalActiveHikingTimeHours = baseHikingTimeHours + elevationTimeHours;
// 4. Calculate time for rest breaks
// Rest breaks are usually calculated per hour of *hiking* time (not total elapsed time)
var totalHikingHoursForBreaks = baseHikingTimeHours; // Using base hiking time for break calculation
var restBreakTimeHours = totalHikingHoursForBreaks * (restBreaks / 60); // Convert minutes per hour to total hours
// 5. Calculate total estimated time
var totalEstimatedTimeHours = totalActiveHikingTimeHours + restBreakTimeHours;
// Convert total hours to hours and minutes for display
var hours = Math.floor(totalEstimatedTimeHours);
var minutes = Math.round((totalEstimatedTimeHours – hours) * 60);
// Adjust if minutes round up to 60
if (minutes === 60) {
hours += 1;
minutes = 0;
}
resultDiv.innerHTML =
"