feat(curriculum): add leap year lab (#55890)
Some checks failed
i18n - Build Validation / Validate i18n Builds (20.x) (push) Has been cancelled
CI - Node.js / Lint (20.x) (push) Has been cancelled
i18n - Upload Client UI / Client (push) Has been cancelled
i18n - Upload Curriculum / Learn (push) Has been cancelled
CI - Node.js / Build (20.x) (push) Has been cancelled
CI - Node.js / Test (20.x) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (20.x) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 20.x) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 20.x) (push) Has been cancelled

Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com>
Co-authored-by: Sem Bauke <sem@freecodecamp.org>
This commit is contained in:
Zaira 2024-09-05 15:23:33 +05:00 committed by GitHub
parent 715eeca1ef
commit 2910ff01df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 135 additions and 1 deletions

View File

@ -1950,7 +1950,12 @@
"In this lab, you will create different stories by assigning different words to different variables."
]
},
"cktz": { "title": "155", "intro": [] },
"lab-leap-year-calculator": {
"title": "Build a Leap Year Calculator ",
"intro": [
"In this lab you will use conditional statements and loops to determine if a year is a leap year."
]
},
"pljo": { "title": "156", "intro": [] },
"avln": { "title": "157", "intro": [] },
"mexq": { "title": "158", "intro": [] },

View File

@ -0,0 +1,9 @@
---
title: Introduction to the a Leap Year Calculator
block: lab-leap-year-calculator
superBlock: front-end-development
---
## Introduction to Leap Year Calculator
In this lab you will utilize conditional statements and loops to create a leap year calculator.

View File

@ -0,0 +1,11 @@
{
"name": "Build a Leap Year Calculator ",
"isUpcomingChange": true,
"usesMultifileEditor": true,
"blockType": "lab",
"dashedName": "lab-leap-year-calculator",
"order": 155,
"superBlock": "front-end-development",
"challengeOrder": [{ "id": "66c06fad3475cd92421b9ac2", "title": "Build a Leap Year Calculator" }],
"helpCategory": "JavaScript"
}

View File

@ -0,0 +1,109 @@
---
id: 66c06fad3475cd92421b9ac2
title: Build a Leap Year Calculator
challengeType: 14
dashedName: build-a-leap-year-calculator
---
# --description--
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:**
1. Define a function called `isLeapYear` that takes a number as an argument.
2. Outside the function, declare a variable `year` that stores the value of the year you want to check.
3. Inside the funtion, use an `if/ else` statement or a ternary operator to check if the year is a leap year.
4. To check if the year is a leap year, fulfill the following conditions:
- If the year is divisible by `4`, then it is a leap year.
- If the year is divisible by `100`, then it is not a leap year.
- If the year is divisible by `400`, then it is a leap year.
5. 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.
6. You should call the `isLeapYear` function with `year` as the argument and assign the result to a variable named `result`.
7. You should output the `result` variable to the console using `console.log()`.
# --hints--
You should define a function named `isLeapYear`.
```js
assert(typeof isLeapYear === 'function');
```
The `isLeapYear` funtion should take a number as an argument.
```js
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.
```js
assert.isDefined(year);
```
The `year` variable shouldn't be empty.
```js
assert.isNotNull(year);
```
With `2024` as the value of the `year` variable, the `result` should be `2024 is a leap year.`.
```js
assert.strictEqual(isLeapYear(2024), '2024 is a leap year.');
```
With `1900` as the value of the `year` variable, the `result` should be `1900 is not a leap year.`.
```js
assert.strictEqual(isLeapYear(1900), '1900 is not a leap year.');
```
You should call the `isLeapYear` function and pass `year` as a parameter.
```js
assert.match(__helpers.removeJSComments(code), /isLeapYear\(\s*year\s*\)/);
```
You should store the result of calling the `isLeapYear` function in a variable named `result`.
```js
assert.match(__helpers.removeJSComments(code), /const\s+result\s*=\s*isLeapYear\(\s*year\s*\)/);
```
You should output the `result` to the console using `console.log()`.
```js
assert.match(__helpers.removeJSComments(code), /console\.log\(\s*result\s*\)/);
```
# --seed--
## --seed-contents--
```js
```
# --solutions--
```js
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);
```