N
N
nikita1sm2019-11-25 07:45:42
JavaScript
nikita1sm, 2019-11-25 07:45:42

How to return the first Friday the 13th?

At the input of the function year (in number)
The function should return the first Friday the 13th of this year as a Date object
Please tell me where to start
Example:
third(2019) // Fri Sep 13 2019 03:00:00 GMT+0300 (Moscow Standard time)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2019-11-25
@nikita1sm

function friday13(year) {
    for (let month = 0; month < 12; month++) {
        let d = new Date(year, month, 13);
        if (d.getDay() === 5) return d;
    }
}

console.log(friday13(2019));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question