Javascript 将数据从函数传递到日期函数(让日期=新日期(“值”))
我试图解决这个Reddit每日编程挑战,但我无法克服这个障碍。挑战的任务是: 程序应该有三个参数。第一个是一天,第二个是月,第三个是年。 然后,您的程序应该计算该日期将出现在一周中的哪一天 所以我已经找到了一个解决工作日问题的函数。任务是,创建一个包含3个参数的程序。所以我需要将一些值传递到新的日期变量中,如下所示:1987年12月25日 我创建了一个包含3个参数的函数:月、日、年。我还找到了如何以正确的格式存储这些值,以便与新的日期变量一起使用 唯一的问题是,我不知道如何将findOutDatemonth、day、year函数的输出传递给新的日期变量 这让我发疯。请帮帮我。另外,也许我把挑战搞错了,有一个更简单的方法来解决它Javascript 将数据从函数传递到日期函数(让日期=新日期(“值”)),javascript,reddit,Javascript,Reddit,我试图解决这个Reddit每日编程挑战,但我无法克服这个障碍。挑战的任务是: 程序应该有三个参数。第一个是一天,第二个是月,第三个是年。 然后,您的程序应该计算该日期将出现在一周中的哪一天 所以我已经找到了一个解决工作日问题的函数。任务是,创建一个包含3个参数的程序。所以我需要将一些值传递到新的日期变量中,如下所示:1987年12月25日 我创建了一个包含3个参数的函数:月、日、年。我还找到了如何以正确的格式存储这些值,以便与新的日期变量一起使用 唯一的问题是,我不知道如何将findOutDat
// The program should take three arguments. The first will be a day, the second will be month,
// and the third will be year.
// Then, your program should compute the day of the week that date will fall on.
/**
* Function takes in a Date object and returns the day of the week in a text format.
*/
function getWeekDay(date) {
// Create an array containing each day, starting with Sunday.
const weekdays = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
// Use the getDay() method to get the day.
const day = date.getDay();
// Return the element that corresponds to that index.
return weekdays[day];
}
// The function that takes 3 arguments and stores them in a variable
function findOutDate(month, day, year) {
// console.log(month + " " + day + ", " + year);
let date = month + " " + day + ", " + year
}
// Finding out what day a specific date fell on.
let date = new Date('December 25, 1987');
let weekDay = getWeekDay(date);
console.log('Christmas Day in 1987 fell on a ' + weekDay);
希望能有所帮助是的,我已经读过了。但这对我的困境没有帮助:月份数字从零开始,所以你必须从大多数人认为的月份值中减去1。非常感谢你!问题很简单,我没有在findOutDate函数中返回日期?!
function findOutDate(month, day, year) {
// console.log(month + " " + day + ", " + year);
let date = month + " " + day + ", " + year
return date //return the date string
}
//Finding out what day a specific date fell on.
let date = new Date(findOutDate()); //call the function returning the date string
let weekDay = getWeekDay(date);