我想在calculatePrice參數中插入total_dist值。如何將total_dist函數中的total_dist調用到calcautePrice total_dist參數中。如何將函數變量調用到其他函數參數或參數中?
function total_dist(){
total_dist = getDistanceFromLatLonInKm(origin_lat,origin_lng,pickup_lat,pickup_lng);
return total_dist;
}
function calculatePrice(base_cost, base_dist, additional_cost, additional_dist, total_dist) {
if (total_dist > base_dist) {
var dist_diff = total_dist - base_dist;
var time = Math.ceil(dist_diff/additional_dist);
return (time * additional_cost) + base_cost;
}else {
return base_cost;
}
}
非常感謝你。
我不明白你的問題..why你要做到這一點 –
我知道了老兄感謝你的幫助。 – cyberoot