curriculum/challenges/english/blocks/lab-leap-year-calculator/66c06fad3475cd92421b9ac2.md
A leap year is a year that is divisible by 4, except for years that are divisible by 100 and not divisible by 400. For example, 2000 is a leap year, but 1900 is not. Also, a leap year has an extra day in February, which is the 29th day of the month.
Objective: Fulfill the user stories below and get all the tests to pass to complete the lab.
User Stories:
Define a function called isLeapYear that takes a number as an argument.
Outside the function, declare a variable year that stores the value of the year you want to check.
Inside the function, use an if/ else statement or a ternary operator to check if the year is a leap year.
To check if the year is a leap year, fulfill the following conditions:
4, then it is a leap year.100, then it is not a leap year.400, then it is a leap year.If the year is a leap year, return [year] is a leap year.. Otherwise, return [year] is not a leap year.. You will replace [year] with the parameter defined in the isLeapYear function.
You should call the isLeapYear function with year as the argument and assign the result to a variable named result.
You should output the result variable to the console using console.log().
You should define a function named isLeapYear.
assert.isFunction(isLeapYear);
The isLeapYear function should take a number as an argument.
assert.match(isLeapYear.toString(), /\s*isLeapYear\(\s*\w+\s*\)/);
You should declare a variable year and assign it a value to check if it is a leap year.
assert.isDefined(year);
assert.isNumber(year);
assert.isAtLeast(year, 0);
assert.isTrue(Number.isInteger(year));
The year variable shouldn't be empty.
assert.isNotNull(year);
With 2024 as the value of the year variable, the result should be 2024 is a leap year.
assert.strictEqual(isLeapYear(2024), '2024 is a leap year.');
With 2000 as the value of the year variable, the result should be 2000 is a leap year.
assert.strictEqual(isLeapYear(2000), '2000 is a leap year.');
With 1900 as the value of the year variable, the result should be 1900 is not a leap year.
assert.strictEqual(isLeapYear(1900), '1900 is not a leap year.');
You should call the isLeapYear function and pass year as a parameter.
assert.match(__helpers.removeJSComments(code), /isLeapYear\(\s*year\s*\)/);
You should declare a result variable.
assert.isDefined(result);
You should store the result of calling the isLeapYear function in a variable named result.
assert.match(__helpers.removeJSComments(code), /result\s*=\s*isLeapYear\(\s*year\s*\)/);
You should output the result to the console using console.log().
assert.match(__helpers.removeJSComments(code), /console\.log\(\s*result\s*\)/);
function isLeapYear(year) {
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
return(year + " is a leap year.");
} else {
return(year + " is not a leap year.");
}
}
const year = 2024;
const result = isLeapYear(year);
console.log(result);