基本上,我需要修复这个脚本,我试图修复它,但它返回 -1 天。您可以在此处查看新脚本 -
function calculatePrice(startDate, endDate, bike) {
if(cars != "no") {
console.log(startDate);
console.log(endDate);
var currentSeason = getSeason(startDate);
var totalPrice = 0;
var daysInSeason = 0;
var currentDate = startDate;
var tierss = "";
var now = startDate;
var daye = 0;
while(now <= endDate) {
var season = getSeason(currentDate);
daye++;
now.setDate(now.getDate() + 1);
}
if(daye <= 3) tierss = "t1";
else if (daye <= 8) tierss = "t2";
else tierss = "t3"
while (currentDate <= endDate) {
var season = getSeason(currentDate);
if (season != currentSeason) {
totalPrice += getPrice(bike, currentSeason, daysInSeason, tierss);
currentSeason = season;
daysInSeason = 0;
}
daysInSeason++;
console.log('days in season - ' + daysInSeason);
currentDate.setDate(currentDate.getDate() + 1);
}
totalPrice += getPrice(bike, currentSeason, daysInSeason, tierss);
return totalPrice;
}
else {
totalPrice = 0;
return totalPrice;
}
}
返回-1,这是返回一切正常的脚本-
function calculatePrice(startDate, endDate, bike) {
if(cars != "no") {
console.log(startDate);
console.log(endDate);
var currentSeason = getSeason(startDate);
var totalPrice = 0;
var daysInSeason = 0;
var currentDate = startDate;
while (currentDate <= endDate) {
var season = getSeason(currentDate);
if (season != currentSeason) {
totalPrice += getPrice(bike, currentSeason, daysInSeason);
currentSeason = season;
daysInSeason = 0;
}
daysInSeason++;
currentDate.setDate(currentDate.getDate() + 1);
}
totalPrice += getPrice(bike, currentSeason, daysInSeason);
return totalPrice;
}
else {
totalPrice = 0;
return totalPrice;
}
}
为什么我需要编辑脚本?简单地说,因为它返回当前季节的天数,但我需要在 totalPrice 中包含当前季节的总天数和天数。或者另一种可能性是我需要在 getprice 中包含该层,如上所示,两者都应该工作。
希望听到帮助:)!