简体   繁体   English

我被一个java脚本问题困住了。 你能帮我吗?

[英]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.

相关问题 我无法通过用户使用 html 和 javascript 输入给定日期来找到以前的日期。 你能帮帮我吗 - I'm unable to find a previous date by inputing a given date by a user using html and javascript. Can you please help me out 我如何处理来自 java-script 的外部逗号 - How I can deal with outside commas from java-script 我卡在 firebase 云火库上的上传图像中。 谁能帮我。? - i m stuck in upload image on firebase cloud firestore. Can anyone help me .? 我正在尝试在 React 中实现搜索过滤器,但它不起作用,你能帮帮我吗? - I'm trying to implement a Search Filter in React, but it doesn't work, could you help me out? 需要帮助使用 java-script 在 html 文件中显示 XML 内容 - Need help displaying XML content in html file with java-script 救命。 黑莓手机的Java语言电话号码验证 - Help. Java-script phone number validation for blackberry 如何使用java脚本检索动态CRM自定义字段值? - How can I retrieve dynamic CRM custom field values using java-script? 如何在Selenium IDE 1.5.0中处理Java脚本验证以及如何执行? - can I handle java-script validation in selenium IDE 1.5.0 & how? 我无法在用于表单验证的 java 脚本中获得“else if”部分代码 - I can't get “else if ” part of the code in java-script for form-validation 如何缩短此 java 脚本代码长度并添加 animation? - How can i shorten this java-script code length and add animation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM