$1.19

how to write a function to test whether a date is a weekend.

Ask a question+
1

For example:

console.log(is_weekend('Nov 15, 2019')); 
console.log(is_weekend('Nov 16, 2019')); 
console.log(is_weekend('Nov 17, 2019'));
add comment

1 Answer

2
const is_weekend = (date1) => {
    const dt = new Date(date1);

    if(dt.getDay() == 6 || dt.getDay() == 0){
        return "weekend";
    } else {
        return "working day"
    }
}

console.log(is_weekend('Nov 15, 2019'));
console.log(is_weekend('Nov 16, 2019'));
console.log(is_weekend('Nov 17, 2019'));
add comment

Your Answer