-1

This is my code so far:

/*function isSchrikkeljaar(year) {
    year = 2016;
    if (//is empty(year)) {
       //use current year
    }
    if (year%4===0 && (year%100!=0 || year%400===0)) {
       return true;
       console.log(true);
    } else {
       return false;
        console.log(false);
    }
}*/

If the year is a leap year it logs true, if not it should log false, if the year is empty it should take the current year. Can anyone help me out, been stuck for a while. The problem is that I don't know how to give it the current year when the year is empty.

4

1 Answer 1

1
 function isSchrikkeljaar(year) { 
    year = year||new Date().getFullYear();
    if (year%4===0 && (year%100!=0 || year%400===0)) { 
       return true; 
    } else { 
       return false;
    } 
 }

If year is set take year as year, if not take the actual date and get its year.

Use cases:

isSchrikkelyear();//2017 = false
isSchrikkelyear(2016); //false
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.