简体   繁体   中英

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. 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. meaning December is the 11th month while January is 0: my answer:

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.

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. Then ask this object its month and day and check that it matches what you want, namely the 24th day and the 11th month.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM