diff --git a/client/i18n/locales/english/intro.json b/client/i18n/locales/english/intro.json index 253b91a978a..465a462464d 100644 --- a/client/i18n/locales/english/intro.json +++ b/client/i18n/locales/english/intro.json @@ -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": [] }, diff --git a/client/src/pages/learn/front-end-development/lab-leap-year-calculator/index.md b/client/src/pages/learn/front-end-development/lab-leap-year-calculator/index.md new file mode 100644 index 00000000000..dcc81189523 --- /dev/null +++ b/client/src/pages/learn/front-end-development/lab-leap-year-calculator/index.md @@ -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. diff --git a/curriculum/challenges/_meta/lab-leap-year-calculator/meta.json b/curriculum/challenges/_meta/lab-leap-year-calculator/meta.json new file mode 100644 index 00000000000..5730f2bcbe3 --- /dev/null +++ b/curriculum/challenges/_meta/lab-leap-year-calculator/meta.json @@ -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" +} diff --git a/curriculum/challenges/english/25-front-end-development/lab-leap-year-calculator/66c06fad3475cd92421b9ac2.md b/curriculum/challenges/english/25-front-end-development/lab-leap-year-calculator/66c06fad3475cd92421b9ac2.md new file mode 100644 index 00000000000..3fdb2e0eac1 --- /dev/null +++ b/curriculum/challenges/english/25-front-end-development/lab-leap-year-calculator/66c06fad3475cd92421b9ac2.md @@ -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); +``` +