gpt4 book ai didi

javascript - 无法获取输出。函数中给出的参数未被读取

转载 作者:行者123 更新时间:2023-12-02 23:03:44 24 4
gpt4 key购买 nike

我试图制作一个程序,如果日期总数与 find 变量匹配,则可以返回日期。日期 01/08/1996 给出的总数 = 34 ..(即)0+1+0+ 8+1+9+9+6 = 34;请告诉我哪里出错了。

    var find = 25;

for (var year = 2010 ; year <= 2019 ; year++){
for (var month = 1 ; month <=12 ; month++){
var dateLength;
switch(true){
case (month === 1 ||month === 3 ||month === 5 || month ===7|| month ===8||month ===10 || month ===12 ):
dateLength = 31;
break;
case (month === 2 && year%4 ===0):
dateLength = 29;
break;
case (month === 2 && year%4 !==0 ):
dateLength = 28;
break;
default:
dateLength = 30;
}
for (var day = 1 ; day <= dateLength; day ++){
dayFunction(day)
monthFunction(month)
yearFunction(year)
finalTotalFunction(finalDayTotal,finalMonthTotal,finalYearTotal)
if (GrandTotal === find){
console.log(day,"/",month,"/",year)
}
}
}
}
var finalDayTotal =0;
var finalMonthTotal =0;
var finalYearTotal =0;
var GrandTotal;

var dayFunction = (day) =>{
daySplitter=day.toString().split("");
var split =daySplitter.map(Number)
for (let n of split){
finalDayTotal += n;
}
}
var monthFunction = (month) =>{
monthSplitter=month.toString().split("");
var split =monthSplitter.map(Number)
for (let n of split){
finalMonthTotal += n;
}
}
var yearFunction = (year) =>{
yearSplitter=year.toString().split("");
var split =yearSplitter.map(Number)
for (let n of split){
finalYearTotal += n;
}

}
function finalTotalFunction(fd,fm,fy){
GrandTotal = fd+fm+fy;
}

最佳答案

    var finalDayTotal =0;
var finalMonthTotal =0;
var finalYearTotal =0;
var GrandTotal;

var dayFunction = (day) =>{
finalDayTotal = 0
daySplitter=day.toString().split("");
var split =daySplitter.map(Number)
for (let n of split){
finalDayTotal += n;
}
}
var monthFunction = (month) =>{
finalMonthTotal = 0
monthSplitter=month.toString().split("");
var split =monthSplitter.map(Number)
for (let n of split){
finalMonthTotal += n;
}
}
var yearFunction = (year) =>{
finalYearTotal = 0
yearSplitter=year.toString().split("");
var split =yearSplitter.map(Number)
for (let n of split){
finalYearTotal += n;
}

}
function finalTotalFunction(fd,fm,fy){
GrandTotal = fd+fm+fy;
}

var find = 25;

for (var year = 2010 ; year <= 2019 ; year++){
for (var month = 1 ; month <=12 ; month++){
var dateLength;
switch(true){
case (month === 1 ||month === 3 ||month === 5 || month ===7|| month ===8||month ===10 || month ===12 ):
dateLength = 31;
break;
case (month === 2 && year%4 ===0):
dateLength = 29;
break;
case (month === 2 && year%4 !==0 ):
dateLength = 28;
break;
default:
dateLength = 30;
}
for (var day = 1 ; day <= dateLength; day ++){
dayFunction(day)
monthFunction(month)
yearFunction(year)
finalTotalFunction(finalDayTotal,finalMonthTotal,finalYearTotal)
if (GrandTotal === find){
console.log(day,"/",month,"/",year)
}

}
}
}

关于javascript - 无法获取输出。函数中给出的参数未被读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57685519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com