128k views
1 vote
Your task is to write and test a function which takes one argument (a year) and returns True if the year is a leap year, or False otherwise. The seed of the function is already sown in the skeleton code in the editor. Note: we've also prepared a short testing code, which you can use to test your function. The code uses two lists - one with the test data, and the other containing the expected results. The code will tell you if any of your results are invalid.

User HexBlit
by
4.5k points

1 Answer

7 votes

Answer:

function isLeapYear( aYear ) (year % 100 !== 0 && year % 4 === 0);

return confirmYear ? True : False;

Step-by-step explanation:

The javascript function above requires an argument which is the year when it is passed, it is analyzed, counting the number of days in that year and a boolean value of true or false is dynamically assigned to the variable 'confirmYear'.

The ternary operator would logically select the right value, which is outputted to the user. To test the function, use the console to call the function with an argument.

console.log( isLeapYear( 1999 ) );

User Issa Khodadadi
by
4.5k points