[英]I'm stuck with a java-script question. Can you help me out?
[the inputs are there theoutput is there Christmas Eve is almost upon us, so naturally we need to prepare some milk and cookies for Santa. [输入有输出有输出圣诞节快到了,所以我们自然需要为圣诞老人准备一些牛奶和cookies。 Create a function that accepts a Date object and returns true if it's Christmas Eve (December 24th) and false otherwise, Keep in mind JavaScript's Date month is 0 based.
创建一个接受日期 object 的 function 并在平安夜(12 月 24 日)返回 true,否则返回 false,请记住 JavaScript 的日期月份是基于 0 的。 meaning December is the 11th month while January is 0: my answer:
意思是 12 月是第 11 个月,而 1 月是 0:我的回答:
function timeForMilkAndCookies(date) {
var month=11;
var day=24;
if(date=("year, "+ month +", "+ day)){
return true;
}
else{
return false;
}
}
this was my code, but my code is not giving the correct output when the inputs are false, it still showing true.这是我的代码,但是当输入为假时,我的代码没有给出正确的 output,它仍然显示为真。
return date instanceof Date && date.getMonth() === 11 && date.getDate() === 24;
first make sure the object you are given a date object, this is what date instanceof Date
checks for.首先确保 object 给你一个日期 object,这是
date instanceof Date
检查的日期。 Then ask this object its month and day and check that it matches what you want, namely the 24th day and the 11th month.然后询问这个 object 的月份和日期,并检查它是否与您想要的相符,即第 24 天和第 11 个月。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.