mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-01 08:05:25 -05:00
fix(curriculum): updating hints and explanations for date formatter project (#52318)
This commit is contained in:
@@ -9,7 +9,7 @@ dashedName: step-4
|
||||
|
||||
The `Date` object has a number of methods that allow you to get the date and time in different formats.
|
||||
|
||||
One of those is the `.getDate()` method, which returns a number between 1-31 that represents the day of the month for that date. For example:
|
||||
One of those is the `.getDate()` method, which returns a number between `1` and `31` that represents the day of the month for that date. For example:
|
||||
|
||||
```js
|
||||
const date = new Date();
|
||||
|
||||
@@ -7,7 +7,7 @@ dashedName: step-8
|
||||
|
||||
# --description--
|
||||
|
||||
The `.getMinutes()` method returns a number between 0 and 59 which represents the minutes for the provided date.
|
||||
The `.getMinutes()` method returns a number between `0` and `59` which represents the minutes for the provided date.
|
||||
|
||||
Create a `const` variable named `minutes` and assign it the minutes from `date` with the `.getMinutes()` method.
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ After the `day` variable, add a dash (`-`) followed by another embedded expressi
|
||||
|
||||
# --hints--
|
||||
|
||||
You will need to use the `month` constant inside the template literal after a dash.
|
||||
You should add a dash followed by the `month` constant to the template literal.
|
||||
|
||||
```js
|
||||
assert(code.match(/const\s+formattedDate\s+=\s+`\${day}\s*-\s*\${month}`/g));
|
||||
|
||||
@@ -11,7 +11,7 @@ After the `month` variable, add a dash followed by another embedded expression t
|
||||
|
||||
# --hints--
|
||||
|
||||
You will need to use the `year` constant inside the template literal after a dash.
|
||||
You should add a dash followed by the `year` constant to the template literal.
|
||||
|
||||
```js
|
||||
assert(code.match(/const\s+formattedDate\s+=\s+`\${day}\s*-\s*\${month}\s*-\s*\${year}`/g));
|
||||
|
||||
@@ -7,7 +7,7 @@ dashedName: step-15
|
||||
|
||||
# --description--
|
||||
|
||||
In JavaScript, the `change` event is used to detect when the value of an HTML element has changed.
|
||||
In JavaScript, the `change` event is used to detect when the value of an HTML element has changed:
|
||||
|
||||
```js
|
||||
element.addEventListener("change", () => {
|
||||
|
||||
@@ -9,10 +9,10 @@ dashedName: step-17
|
||||
|
||||
When the user chooses the `Year, Month, Day` option from the dropdown, the date format should reflect this choice.
|
||||
|
||||
To do this, you can add a `case` in the `switch` statement, followed by your logic.
|
||||
To do this, you can add a `case` clause in the `switch` statement that checks for a match against the expression `expr`, followed by code to run if there's a match. Here's an example where the `case` clause checks that `expr` is equal to the string `case123`:
|
||||
|
||||
```js
|
||||
switch (expression) {
|
||||
switch (expr) {
|
||||
case 'case123':
|
||||
// Write your logic here
|
||||
}
|
||||
|
||||
@@ -7,12 +7,6 @@ dashedName: step-18
|
||||
|
||||
# --description--
|
||||
|
||||
In JavaScript, the `.split()` method is used to split up a string into an array of substrings. This method has an optional separator parameter, which indicates where each split should happen.
|
||||
|
||||
```js
|
||||
"coca-cola".split("-"); // [ 'coca', 'cola' ]
|
||||
```
|
||||
|
||||
Split `formattedDate` into an array of substrings with the `.split()` method and use a `"-"` as the separator.
|
||||
|
||||
# --hints--
|
||||
|
||||
@@ -9,7 +9,7 @@ dashedName: step-21
|
||||
|
||||
If your `switch` statement is going to have multiple cases, it is best practice to include a `break` statement.
|
||||
|
||||
The `break` statement will tell the JavaScript interpreter to stop executing statements. Without adding a `break` statement at the end of each `case` block, the program will execute the code for all matching `cases`.
|
||||
The `break` statement will tell the JavaScript interpreter to stop executing statements. Without adding a `break` statement at the end of each `case` block, the program will execute the code for all matching `cases`:
|
||||
|
||||
```js
|
||||
switch (someVariable) {
|
||||
@@ -26,7 +26,7 @@ Add a `break` statement to the end of your `case` block.
|
||||
You should add a `break` statement within the `case` after your logic.
|
||||
|
||||
```js
|
||||
assert(code.match(/break/g));
|
||||
assert(code.match(/\.join\((['"])-\1\)\;?\n+\s*break/g));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -22,7 +22,7 @@ assert(code.match(/case\s*(['"])mm-dd-yyyy-h-mm\1\s*:\s*currentDateParagraph.tex
|
||||
You should include a `break` statement within the `case` after your logic.
|
||||
|
||||
```js
|
||||
assert(code.match(/break/g));
|
||||
assert(code.match(/currentDateParagraph.textContent\s*=\s*``\;?\n+\s*break/g));
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
@@ -12,7 +12,7 @@ Inside the `case` for `mm-dd-yyyy-h-mm`, set the `textContent` property of `curr
|
||||
|
||||
# --hints--
|
||||
|
||||
You should assign `${month}-${day}-${year} ${hours} Hours ${minutes} Minutes` inside the `textContent` property of the `currentDateParagraph` constant.
|
||||
You should assign `${month}-${day}-${year} ${hours} Hours ${minutes} Minutes` to the `textContent` property of `currentDateParagraph`.
|
||||
|
||||
```js
|
||||
const pattern = /case\s*(['"])mm-dd-yyyy-h-mm\1\s*:\s*currentDateParagraph\.textContent\s*=\s*`(\$\{month}-\$\{day}-\$\{year} \$\{hours} Hours \$\{minutes} Minutes)`/;
|
||||
|
||||
@@ -31,7 +31,7 @@ And with that, your date formatter is complete! You can now format the current d
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the `default` case to set the `textContent` property of `currentDateParagraph` equal to the constant `formattedDate`.
|
||||
You should use the `default` case to set the `textContent` property of `currentDateParagraph` to the value of `formattedDate`.
|
||||
|
||||
```js
|
||||
assert(code.match(/default\s*:\s*currentDateParagraph.textContent\s*=\s*formattedDate/g));
|
||||
|
||||
Reference in New Issue
Block a user