mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-19 21:09:51 +08:00
refactor(curriculum): expand split, reverse and join method lessons for date formatter project (#54256)
This commit is contained in:
parent
f34f725e9a
commit
ecbd075b21
@ -81,32 +81,52 @@
|
||||
"title": "Step 17"
|
||||
},
|
||||
{
|
||||
"id": "65389211a8d86bbd876a2a74",
|
||||
"id": "6607343c7909e562a2e3d94c",
|
||||
"title": "Step 18"
|
||||
},
|
||||
{
|
||||
"id": "65389306578c34be5c93bc35",
|
||||
"id": "660736bde759eb64c3bd15c3",
|
||||
"title": "Step 19"
|
||||
},
|
||||
{
|
||||
"id": "6538935e2ab721beedb137c4",
|
||||
"id": "66074463e8cc156e18142dbe",
|
||||
"title": "Step 20"
|
||||
},
|
||||
{
|
||||
"id": "653898fa7eee37c57b960e35",
|
||||
"id": "660746a665a61c7075a0f457",
|
||||
"title": "Step 21"
|
||||
},
|
||||
{
|
||||
"id": "65389a63d3b1d6c764c0e10e",
|
||||
"id": "66074af5d2b4f373cb140d6a",
|
||||
"title": "Step 22"
|
||||
},
|
||||
{
|
||||
"id": "65389de504d0f2ca10e92a57",
|
||||
"id": "65389211a8d86bbd876a2a74",
|
||||
"title": "Step 23"
|
||||
},
|
||||
{
|
||||
"id": "65389eff4893facbbe6eae67",
|
||||
"id": "65389306578c34be5c93bc35",
|
||||
"title": "Step 24"
|
||||
},
|
||||
{
|
||||
"id": "6538935e2ab721beedb137c4",
|
||||
"title": "Step 25"
|
||||
},
|
||||
{
|
||||
"id": "653898fa7eee37c57b960e35",
|
||||
"title": "Step 26"
|
||||
},
|
||||
{
|
||||
"id": "65389a63d3b1d6c764c0e10e",
|
||||
"title": "Step 27"
|
||||
},
|
||||
{
|
||||
"id": "65389de504d0f2ca10e92a57",
|
||||
"title": "Step 28"
|
||||
},
|
||||
{
|
||||
"id": "65389eff4893facbbe6eae67",
|
||||
"title": "Step 29"
|
||||
}
|
||||
],
|
||||
"helpCategory": "JavaScript"
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
---
|
||||
id: 65389211a8d86bbd876a2a74
|
||||
title: Step 18
|
||||
title: Step 23
|
||||
challengeType: 0
|
||||
dashedName: step-18
|
||||
dashedName: step-23
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Split `formattedDate` into an array of substrings with the `.split()` method and use a `"-"` as the separator.
|
||||
Now it is time to apply what you learned in the previous steps.
|
||||
|
||||
Split the `formattedDate` string into an array of substrings. Use a `"-"` for the separator.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
@ -1,25 +1,17 @@
|
||||
---
|
||||
id: 65389306578c34be5c93bc35
|
||||
title: Step 19
|
||||
title: Step 24
|
||||
challengeType: 0
|
||||
dashedName: step-19
|
||||
dashedName: step-24
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
The `.reverse()` method is used to reverse an array in place. For example:
|
||||
|
||||
```js
|
||||
const array = [1, 2, 3, 4, 5];
|
||||
array.reverse();
|
||||
console.log(array); // [5, 4, 3, 2, 1]
|
||||
```
|
||||
|
||||
Chain the `.reverse()` method to the end of `.split()` method.
|
||||
Next, reverse the `formattedDate` array. Make sure to use method chaining.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should use the `.reverse()` method to reverse the order of the array returned by `.split()`.
|
||||
You should chain the `.reverse()` method to your `.split()` method.
|
||||
|
||||
```js
|
||||
assert(code.match(/\.reverse\(\s*\)/g));
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
---
|
||||
id: 6538935e2ab721beedb137c4
|
||||
title: Step 20
|
||||
title: Step 25
|
||||
challengeType: 0
|
||||
dashedName: step-20
|
||||
dashedName: step-25
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Finally, you need to create a string with the reversed array elements separated by dash (`-`) character.
|
||||
Finally, join the results from the array reversal. Use a `"-"` as the separator. Remember to use method chaining.
|
||||
|
||||
Use the `.join()` method to join the reversed array elements into a string and use a `"-"` for the separator.
|
||||
Test out your changes by selecting the `Year, Month, Day` option from the dropdown menu. The date should now be displayed in the format `yyyy-mm-dd`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 653898fa7eee37c57b960e35
|
||||
title: Step 21
|
||||
title: Step 26
|
||||
challengeType: 0
|
||||
dashedName: step-21
|
||||
dashedName: step-26
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 65389a63d3b1d6c764c0e10e
|
||||
title: Step 22
|
||||
title: Step 27
|
||||
challengeType: 0
|
||||
dashedName: step-22
|
||||
dashedName: step-27
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 65389de504d0f2ca10e92a57
|
||||
title: Step 23
|
||||
title: Step 28
|
||||
challengeType: 0
|
||||
dashedName: step-23
|
||||
dashedName: step-28
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
---
|
||||
id: 65389eff4893facbbe6eae67
|
||||
title: Step 24
|
||||
title: Step 29
|
||||
challengeType: 0
|
||||
dashedName: step-24
|
||||
dashedName: step-29
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
@ -0,0 +1,285 @@
|
||||
---
|
||||
id: 6607343c7909e562a2e3d94c
|
||||
title: Step 18
|
||||
challengeType: 0
|
||||
dashedName: step-18
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
To format the date into `yyyy-mm-dd`, you will need to use the <dfn>split</dfn>, <dfn>reverse</dfn>, and <dfn>join</dfn> methods. But first, you will need to go through a few practice examples so you can better understand how to use them in the context of this project.
|
||||
|
||||
The `split()` method is used to divide a string into substrings based on a specified separator. It then returns these substrings as elements of an array.
|
||||
|
||||
Here is an example of taking the words `"Hello World"` and returning an array of one element:
|
||||
|
||||
```js
|
||||
const greeting = "Hello World";
|
||||
greeting.split(); // ["Hello World"]
|
||||
```
|
||||
|
||||
Create a new `const` variable called `exampleSentence` and assign it the result of `"selur pmaCedoCeerf".split()`.
|
||||
|
||||
Then add a console statement to log the value of `exampleSentence`. Open up the console to see the result.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should have a `const` variable called `exampleSentence`.
|
||||
|
||||
```js
|
||||
assert.match(code, /const\s+exampleSentence\s*=/);
|
||||
```
|
||||
|
||||
You should assign `"selur pmaCedoCeerf".split()` to your `exampleSentence` variable.
|
||||
|
||||
```js
|
||||
assert.match(code, /const\s+exampleSentence\s*=\s*('|"|`)selur\s+pmaCedoCeerf\1\.split\(\)/);
|
||||
```
|
||||
|
||||
You should have a `console.log` statement that logs the value of `exampleSentence`.
|
||||
|
||||
```js
|
||||
assert.match(code, /console\.log\(\s*exampleSentence\s*\)/);
|
||||
```
|
||||
|
||||
Your console statement should be below the `exampleSentence` variable assignment.
|
||||
|
||||
```js
|
||||
const consoleStatementIndex = code.indexOf("console.log(exampleSentence)");
|
||||
const exampleSentenceIndex = code.indexOf("const exampleSentence");
|
||||
|
||||
assert.isBelow(exampleSentenceIndex, consoleStatementIndex);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Learn the Date Object by Building a Date Formatter</title>
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="title-container">
|
||||
<h1 class="title">Today's Date</h1>
|
||||
|
||||
<svg
|
||||
class="date-svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
width="512.000000pt"
|
||||
height="512.000000pt"
|
||||
viewBox="0 0 512.000000 512.000000"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
<g
|
||||
transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||
fill="#fff"
|
||||
stroke="none"
|
||||
>
|
||||
<path
|
||||
d="M1145 4777 c-71 -24 -120 -54 -164 -102 -59 -64 -83 -124 -89 -216 l-4 -77 -147 -3 c-142 -4 -149 -5 -213 -37 -81 -40 -149 -111 -177 -188 -21 -54 -21 -64 -21 -1789 0 -1725 0 -1735 21 -1789 28 -77 96 -148 177 -188 l67 -33 1950 0 1950 0 67 33 c74 36 133 96 170 170 l23 47 0 1760 0 1760 -23 47 c-37 74 -96 134 -169 170 -63 31 -71 32 -213 36 l-148 4 -4 77 c-8 133 -82 242 -200 297 -54 25 -75 29 -148 29 -94 -1 -151 -20 -220 -75 -75 -59 -130 -181 -130 -287 l0 -43 -954 0 -954 0 -7 74 c-12 137 -89 251 -201 303 -66 30 -179 39 -239 20z m209 -164 c23 -16 52 -49 66 -73 l25 -45 0 -365 0 -365 -28 -47 c-30 -52 -88 -92 -149 -103 -54 -10 -137 17 -175 57 -65 69 -64 60 -61 471 l3 373 27 41 c17 26 45 50 80 68 71 35 151 31 212 -12z m2594 11 c41 -20 59 -37 82 -78 l30 -51 0 -360 c0 -329 -2 -364 -19 -401 -36 -79 -137 -133 -222 -119 -57 10 -125 58 -151 107 -23 42 -23 50 -26 388 -3 377 -1 403 51 465 62 76 162 95 255 49z m537 -2717 l0 -1239 -24 -19 c-23 -19 -67 -19 -1916 -19 -1849 0 -1893 0 -1916 19 l-24 19 -3 1241 -2 1241 1942 -2 1943 -3 0 -1238z"
|
||||
/>
|
||||
<path
|
||||
d="M1112 2493 l3 -158 318 -3 317 -2 0 160 0 160 -320 0 -321 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 2490 l0 -160 315 0 315 0 0 160 0 160 -315 0 -315 0 0 -160z"
|
||||
/>
|
||||
<path
|
||||
d="M3342 2493 l3 -158 310 0 310 0 3 158 3 157 -316 0 -316 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M1110 1855 l0 -155 320 0 320 0 0 155 0 155 -320 0 -320 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M3340 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M1117 1383 c-4 -3 -7 -78 -7 -165 l0 -158 320 0 320 0 0 165 0 165 -313 0 c-173 0 -317 -3 -320 -7z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1225 l0 -165 315 0 315 0 0 165 0 165 -315 0 -315 0 0 -165z"
|
||||
/>
|
||||
<path
|
||||
d="M3347 1383 c-4 -3 -7 -78 -7 -165 l0 -158 315 0 315 0 -2 163 -3 162 -306 3 c-168 1 -308 -1 -312 -5z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="dropdown-container">
|
||||
<select name="date-options" id="date-options">
|
||||
<option value="dd-mm-yyyy">Day, Month, Year</option>
|
||||
<option value="yyyy-mm-dd">Year, Month, Day</option>
|
||||
<option value="mm-dd-yyyy-h-mm">
|
||||
Month, Day, Year, Hours, Minutes
|
||||
</option>
|
||||
</select>
|
||||
<div class="select-icon">
|
||||
<svg
|
||||
class="icon"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="25"
|
||||
height="35"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<rect x="0" fill="none" width="24" height="24" />
|
||||
|
||||
<g>
|
||||
<path d="M7 10l5 5 5-5" />
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="current-date"></p>
|
||||
</main>
|
||||
|
||||
<script src="./script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--dark-grey: #0a0a23;
|
||||
--white: #ffffff;
|
||||
--yellow: #f1be32;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--white);
|
||||
background-color: var(--dark-grey);
|
||||
}
|
||||
|
||||
.title-container {
|
||||
margin: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
margin: auto;
|
||||
width: 150px;
|
||||
height: 10px;
|
||||
background-color: var(--yellow);
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 50%;
|
||||
margin: 40px auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
select {
|
||||
display: block;
|
||||
margin: 20px auto 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
background-color: var(--white);
|
||||
border: none;
|
||||
color: var(--dark-grey);
|
||||
appearance: none;
|
||||
padding: 10px;
|
||||
padding-right: 38px;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
transition: color 0.3s ease, background-color 0.3s ease,
|
||||
border-bottom-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 30px;
|
||||
height: 36px;
|
||||
pointer-events: none;
|
||||
padding-left: 5px;
|
||||
transition: background-color 0.3s ease, border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon svg.icon {
|
||||
transition: fill 0.3s ease;
|
||||
fill: var(--dark-grey);
|
||||
}
|
||||
|
||||
#current-date {
|
||||
font-size: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 375px) {
|
||||
.title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
const currentDateParagraph = document.getElementById("current-date");
|
||||
const dateOptionsSelectElement = document.getElementById("date-options");
|
||||
|
||||
const date = new Date();
|
||||
const day = date.getDate();
|
||||
const month = date.getMonth() + 1;
|
||||
const year = date.getFullYear();
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
const formattedDate = `${day}-${month}-${year}`;
|
||||
currentDateParagraph.textContent = formattedDate;
|
||||
|
||||
--fcc-editable-region--
|
||||
|
||||
--fcc-editable-region--
|
||||
dateOptionsSelectElement.addEventListener("change", () => {
|
||||
switch (dateOptionsSelectElement.value) {
|
||||
case "yyyy-mm-dd":
|
||||
currentDateParagraph.textContent = formattedDate
|
||||
}
|
||||
});
|
||||
```
|
||||
@ -0,0 +1,263 @@
|
||||
---
|
||||
id: 660736bde759eb64c3bd15c3
|
||||
title: Step 19
|
||||
challengeType: 0
|
||||
dashedName: step-19
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
The `split` method takes in a parameter known as a separator. The separator is used to tell the computer where each split should occur.
|
||||
|
||||
Here is an example of using an empty string as a separator:
|
||||
|
||||
```js
|
||||
const str = "hello";
|
||||
str.split(""); // returns ["h", "e", "l", "l", "o"]
|
||||
```
|
||||
|
||||
Other examples of separators can include a space `" "`, or a hyphen `"-"`. If you don't provide a separator, the method will return an array with the original string as the only element.
|
||||
|
||||
Update your `split` method, to use an empty string as a separator. Open up the console again to see the result.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `split` method should take in an empty string as a separator.
|
||||
|
||||
```js
|
||||
assert.match(code, /const\s+exampleSentence\s*=\s*('|")selur\s+pmaCedoCeerf\1\.split\(\s*('|")\2\);?/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Learn the Date Object by Building a Date Formatter</title>
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="title-container">
|
||||
<h1 class="title">Today's Date</h1>
|
||||
|
||||
<svg
|
||||
class="date-svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
width="512.000000pt"
|
||||
height="512.000000pt"
|
||||
viewBox="0 0 512.000000 512.000000"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
<g
|
||||
transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||
fill="#fff"
|
||||
stroke="none"
|
||||
>
|
||||
<path
|
||||
d="M1145 4777 c-71 -24 -120 -54 -164 -102 -59 -64 -83 -124 -89 -216 l-4 -77 -147 -3 c-142 -4 -149 -5 -213 -37 -81 -40 -149 -111 -177 -188 -21 -54 -21 -64 -21 -1789 0 -1725 0 -1735 21 -1789 28 -77 96 -148 177 -188 l67 -33 1950 0 1950 0 67 33 c74 36 133 96 170 170 l23 47 0 1760 0 1760 -23 47 c-37 74 -96 134 -169 170 -63 31 -71 32 -213 36 l-148 4 -4 77 c-8 133 -82 242 -200 297 -54 25 -75 29 -148 29 -94 -1 -151 -20 -220 -75 -75 -59 -130 -181 -130 -287 l0 -43 -954 0 -954 0 -7 74 c-12 137 -89 251 -201 303 -66 30 -179 39 -239 20z m209 -164 c23 -16 52 -49 66 -73 l25 -45 0 -365 0 -365 -28 -47 c-30 -52 -88 -92 -149 -103 -54 -10 -137 17 -175 57 -65 69 -64 60 -61 471 l3 373 27 41 c17 26 45 50 80 68 71 35 151 31 212 -12z m2594 11 c41 -20 59 -37 82 -78 l30 -51 0 -360 c0 -329 -2 -364 -19 -401 -36 -79 -137 -133 -222 -119 -57 10 -125 58 -151 107 -23 42 -23 50 -26 388 -3 377 -1 403 51 465 62 76 162 95 255 49z m537 -2717 l0 -1239 -24 -19 c-23 -19 -67 -19 -1916 -19 -1849 0 -1893 0 -1916 19 l-24 19 -3 1241 -2 1241 1942 -2 1943 -3 0 -1238z"
|
||||
/>
|
||||
<path
|
||||
d="M1112 2493 l3 -158 318 -3 317 -2 0 160 0 160 -320 0 -321 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 2490 l0 -160 315 0 315 0 0 160 0 160 -315 0 -315 0 0 -160z"
|
||||
/>
|
||||
<path
|
||||
d="M3342 2493 l3 -158 310 0 310 0 3 158 3 157 -316 0 -316 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M1110 1855 l0 -155 320 0 320 0 0 155 0 155 -320 0 -320 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M3340 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M1117 1383 c-4 -3 -7 -78 -7 -165 l0 -158 320 0 320 0 0 165 0 165 -313 0 c-173 0 -317 -3 -320 -7z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1225 l0 -165 315 0 315 0 0 165 0 165 -315 0 -315 0 0 -165z"
|
||||
/>
|
||||
<path
|
||||
d="M3347 1383 c-4 -3 -7 -78 -7 -165 l0 -158 315 0 315 0 -2 163 -3 162 -306 3 c-168 1 -308 -1 -312 -5z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="dropdown-container">
|
||||
<select name="date-options" id="date-options">
|
||||
<option value="dd-mm-yyyy">Day, Month, Year</option>
|
||||
<option value="yyyy-mm-dd">Year, Month, Day</option>
|
||||
<option value="mm-dd-yyyy-h-mm">
|
||||
Month, Day, Year, Hours, Minutes
|
||||
</option>
|
||||
</select>
|
||||
<div class="select-icon">
|
||||
<svg
|
||||
class="icon"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="25"
|
||||
height="35"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<rect x="0" fill="none" width="24" height="24" />
|
||||
|
||||
<g>
|
||||
<path d="M7 10l5 5 5-5" />
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="current-date"></p>
|
||||
</main>
|
||||
|
||||
<script src="./script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--dark-grey: #0a0a23;
|
||||
--white: #ffffff;
|
||||
--yellow: #f1be32;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--white);
|
||||
background-color: var(--dark-grey);
|
||||
}
|
||||
|
||||
.title-container {
|
||||
margin: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
margin: auto;
|
||||
width: 150px;
|
||||
height: 10px;
|
||||
background-color: var(--yellow);
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 50%;
|
||||
margin: 40px auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
select {
|
||||
display: block;
|
||||
margin: 20px auto 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
background-color: var(--white);
|
||||
border: none;
|
||||
color: var(--dark-grey);
|
||||
appearance: none;
|
||||
padding: 10px;
|
||||
padding-right: 38px;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
transition: color 0.3s ease, background-color 0.3s ease,
|
||||
border-bottom-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 30px;
|
||||
height: 36px;
|
||||
pointer-events: none;
|
||||
padding-left: 5px;
|
||||
transition: background-color 0.3s ease, border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon svg.icon {
|
||||
transition: fill 0.3s ease;
|
||||
fill: var(--dark-grey);
|
||||
}
|
||||
|
||||
#current-date {
|
||||
font-size: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 375px) {
|
||||
.title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
const currentDateParagraph = document.getElementById("current-date");
|
||||
const dateOptionsSelectElement = document.getElementById("date-options");
|
||||
|
||||
const date = new Date();
|
||||
const day = date.getDate();
|
||||
const month = date.getMonth() + 1;
|
||||
const year = date.getFullYear();
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
const formattedDate = `${day}-${month}-${year}`;
|
||||
currentDateParagraph.textContent = formattedDate;
|
||||
|
||||
--fcc-editable-region--
|
||||
const exampleSentence = "selur pmaCedoCeerf".split();
|
||||
console.log(exampleSentence);
|
||||
--fcc-editable-region--
|
||||
dateOptionsSelectElement.addEventListener("change", () => {
|
||||
switch (dateOptionsSelectElement.value) {
|
||||
case "yyyy-mm-dd":
|
||||
currentDateParagraph.textContent = formattedDate
|
||||
}
|
||||
});
|
||||
```
|
||||
@ -0,0 +1,272 @@
|
||||
---
|
||||
id: 66074463e8cc156e18142dbe
|
||||
title: Step 20
|
||||
challengeType: 0
|
||||
dashedName: step-20
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
To reverse an array of elements, you can use the `reverse` method. This method reverses the order of the elements in the array in place. The first element becomes the last, and the last element becomes the first.
|
||||
|
||||
Here is an example of using the `reverse` method:
|
||||
|
||||
```js
|
||||
// returns [5, 4, 3, 2, 1]
|
||||
[1, 2, 3, 4, 5].reverse();
|
||||
```
|
||||
|
||||
Chain the `reverse` method to your `split` method. Open up the console again to see the result.
|
||||
|
||||
Remember that you learned how to chain methods in the previous project like this:
|
||||
|
||||
```js
|
||||
method1().method2().method3();
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
You should chain the `reverse` method to your `"selur pmaCedoCeerf".split("")` method.
|
||||
|
||||
```js
|
||||
assert.deepEqual(exampleSentence, [
|
||||
'f', 'r', 'e', 'e', 'C',
|
||||
'o', 'd', 'e', 'C', 'a',
|
||||
'm', 'p', ' ', 'r', 'u',
|
||||
'l', 'e', 's'
|
||||
]);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Learn the Date Object by Building a Date Formatter</title>
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="title-container">
|
||||
<h1 class="title">Today's Date</h1>
|
||||
|
||||
<svg
|
||||
class="date-svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
width="512.000000pt"
|
||||
height="512.000000pt"
|
||||
viewBox="0 0 512.000000 512.000000"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
<g
|
||||
transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||
fill="#fff"
|
||||
stroke="none"
|
||||
>
|
||||
<path
|
||||
d="M1145 4777 c-71 -24 -120 -54 -164 -102 -59 -64 -83 -124 -89 -216 l-4 -77 -147 -3 c-142 -4 -149 -5 -213 -37 -81 -40 -149 -111 -177 -188 -21 -54 -21 -64 -21 -1789 0 -1725 0 -1735 21 -1789 28 -77 96 -148 177 -188 l67 -33 1950 0 1950 0 67 33 c74 36 133 96 170 170 l23 47 0 1760 0 1760 -23 47 c-37 74 -96 134 -169 170 -63 31 -71 32 -213 36 l-148 4 -4 77 c-8 133 -82 242 -200 297 -54 25 -75 29 -148 29 -94 -1 -151 -20 -220 -75 -75 -59 -130 -181 -130 -287 l0 -43 -954 0 -954 0 -7 74 c-12 137 -89 251 -201 303 -66 30 -179 39 -239 20z m209 -164 c23 -16 52 -49 66 -73 l25 -45 0 -365 0 -365 -28 -47 c-30 -52 -88 -92 -149 -103 -54 -10 -137 17 -175 57 -65 69 -64 60 -61 471 l3 373 27 41 c17 26 45 50 80 68 71 35 151 31 212 -12z m2594 11 c41 -20 59 -37 82 -78 l30 -51 0 -360 c0 -329 -2 -364 -19 -401 -36 -79 -137 -133 -222 -119 -57 10 -125 58 -151 107 -23 42 -23 50 -26 388 -3 377 -1 403 51 465 62 76 162 95 255 49z m537 -2717 l0 -1239 -24 -19 c-23 -19 -67 -19 -1916 -19 -1849 0 -1893 0 -1916 19 l-24 19 -3 1241 -2 1241 1942 -2 1943 -3 0 -1238z"
|
||||
/>
|
||||
<path
|
||||
d="M1112 2493 l3 -158 318 -3 317 -2 0 160 0 160 -320 0 -321 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 2490 l0 -160 315 0 315 0 0 160 0 160 -315 0 -315 0 0 -160z"
|
||||
/>
|
||||
<path
|
||||
d="M3342 2493 l3 -158 310 0 310 0 3 158 3 157 -316 0 -316 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M1110 1855 l0 -155 320 0 320 0 0 155 0 155 -320 0 -320 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M3340 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M1117 1383 c-4 -3 -7 -78 -7 -165 l0 -158 320 0 320 0 0 165 0 165 -313 0 c-173 0 -317 -3 -320 -7z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1225 l0 -165 315 0 315 0 0 165 0 165 -315 0 -315 0 0 -165z"
|
||||
/>
|
||||
<path
|
||||
d="M3347 1383 c-4 -3 -7 -78 -7 -165 l0 -158 315 0 315 0 -2 163 -3 162 -306 3 c-168 1 -308 -1 -312 -5z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="dropdown-container">
|
||||
<select name="date-options" id="date-options">
|
||||
<option value="dd-mm-yyyy">Day, Month, Year</option>
|
||||
<option value="yyyy-mm-dd">Year, Month, Day</option>
|
||||
<option value="mm-dd-yyyy-h-mm">
|
||||
Month, Day, Year, Hours, Minutes
|
||||
</option>
|
||||
</select>
|
||||
<div class="select-icon">
|
||||
<svg
|
||||
class="icon"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="25"
|
||||
height="35"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<rect x="0" fill="none" width="24" height="24" />
|
||||
|
||||
<g>
|
||||
<path d="M7 10l5 5 5-5" />
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="current-date"></p>
|
||||
</main>
|
||||
|
||||
<script src="./script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--dark-grey: #0a0a23;
|
||||
--white: #ffffff;
|
||||
--yellow: #f1be32;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--white);
|
||||
background-color: var(--dark-grey);
|
||||
}
|
||||
|
||||
.title-container {
|
||||
margin: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
margin: auto;
|
||||
width: 150px;
|
||||
height: 10px;
|
||||
background-color: var(--yellow);
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 50%;
|
||||
margin: 40px auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
select {
|
||||
display: block;
|
||||
margin: 20px auto 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
background-color: var(--white);
|
||||
border: none;
|
||||
color: var(--dark-grey);
|
||||
appearance: none;
|
||||
padding: 10px;
|
||||
padding-right: 38px;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
transition: color 0.3s ease, background-color 0.3s ease,
|
||||
border-bottom-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 30px;
|
||||
height: 36px;
|
||||
pointer-events: none;
|
||||
padding-left: 5px;
|
||||
transition: background-color 0.3s ease, border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon svg.icon {
|
||||
transition: fill 0.3s ease;
|
||||
fill: var(--dark-grey);
|
||||
}
|
||||
|
||||
#current-date {
|
||||
font-size: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 375px) {
|
||||
.title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
const currentDateParagraph = document.getElementById("current-date");
|
||||
const dateOptionsSelectElement = document.getElementById("date-options");
|
||||
|
||||
const date = new Date();
|
||||
const day = date.getDate();
|
||||
const month = date.getMonth() + 1;
|
||||
const year = date.getFullYear();
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
const formattedDate = `${day}-${month}-${year}`;
|
||||
currentDateParagraph.textContent = formattedDate;
|
||||
|
||||
--fcc-editable-region--
|
||||
const exampleSentence = "selur pmaCedoCeerf".split("");
|
||||
console.log(exampleSentence);
|
||||
--fcc-editable-region--
|
||||
dateOptionsSelectElement.addEventListener("change", () => {
|
||||
switch (dateOptionsSelectElement.value) {
|
||||
case "yyyy-mm-dd":
|
||||
currentDateParagraph.textContent = formattedDate
|
||||
}
|
||||
});
|
||||
```
|
||||
@ -0,0 +1,263 @@
|
||||
---
|
||||
id: 660746a665a61c7075a0f457
|
||||
title: Step 21
|
||||
challengeType: 0
|
||||
dashedName: step-21
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In the previous project, you learned how to work with the `join` method. This method takes an array of elements and joins them into a string. Similar to the `split` method, the `join` method also takes an optional separator. If you don't provide a separator, the default separator is a comma.
|
||||
|
||||
Here is an example of using the `join` method:
|
||||
|
||||
```js
|
||||
// returns "1-2-3-4-5"
|
||||
[1, 2, 3, 4, 5].join("-");
|
||||
```
|
||||
|
||||
Chain the `join` method to your `reverse` method. Pass in an empty string as the separator.
|
||||
|
||||
Open up the console and see the output.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should chain `join('')` to the `reverse` method.
|
||||
|
||||
```js
|
||||
assert.strictEqual(exampleSentence, 'freeCodeCamp rules');
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Learn the Date Object by Building a Date Formatter</title>
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="title-container">
|
||||
<h1 class="title">Today's Date</h1>
|
||||
|
||||
<svg
|
||||
class="date-svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
width="512.000000pt"
|
||||
height="512.000000pt"
|
||||
viewBox="0 0 512.000000 512.000000"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
<g
|
||||
transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||
fill="#fff"
|
||||
stroke="none"
|
||||
>
|
||||
<path
|
||||
d="M1145 4777 c-71 -24 -120 -54 -164 -102 -59 -64 -83 -124 -89 -216 l-4 -77 -147 -3 c-142 -4 -149 -5 -213 -37 -81 -40 -149 -111 -177 -188 -21 -54 -21 -64 -21 -1789 0 -1725 0 -1735 21 -1789 28 -77 96 -148 177 -188 l67 -33 1950 0 1950 0 67 33 c74 36 133 96 170 170 l23 47 0 1760 0 1760 -23 47 c-37 74 -96 134 -169 170 -63 31 -71 32 -213 36 l-148 4 -4 77 c-8 133 -82 242 -200 297 -54 25 -75 29 -148 29 -94 -1 -151 -20 -220 -75 -75 -59 -130 -181 -130 -287 l0 -43 -954 0 -954 0 -7 74 c-12 137 -89 251 -201 303 -66 30 -179 39 -239 20z m209 -164 c23 -16 52 -49 66 -73 l25 -45 0 -365 0 -365 -28 -47 c-30 -52 -88 -92 -149 -103 -54 -10 -137 17 -175 57 -65 69 -64 60 -61 471 l3 373 27 41 c17 26 45 50 80 68 71 35 151 31 212 -12z m2594 11 c41 -20 59 -37 82 -78 l30 -51 0 -360 c0 -329 -2 -364 -19 -401 -36 -79 -137 -133 -222 -119 -57 10 -125 58 -151 107 -23 42 -23 50 -26 388 -3 377 -1 403 51 465 62 76 162 95 255 49z m537 -2717 l0 -1239 -24 -19 c-23 -19 -67 -19 -1916 -19 -1849 0 -1893 0 -1916 19 l-24 19 -3 1241 -2 1241 1942 -2 1943 -3 0 -1238z"
|
||||
/>
|
||||
<path
|
||||
d="M1112 2493 l3 -158 318 -3 317 -2 0 160 0 160 -320 0 -321 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 2490 l0 -160 315 0 315 0 0 160 0 160 -315 0 -315 0 0 -160z"
|
||||
/>
|
||||
<path
|
||||
d="M3342 2493 l3 -158 310 0 310 0 3 158 3 157 -316 0 -316 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M1110 1855 l0 -155 320 0 320 0 0 155 0 155 -320 0 -320 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M3340 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M1117 1383 c-4 -3 -7 -78 -7 -165 l0 -158 320 0 320 0 0 165 0 165 -313 0 c-173 0 -317 -3 -320 -7z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1225 l0 -165 315 0 315 0 0 165 0 165 -315 0 -315 0 0 -165z"
|
||||
/>
|
||||
<path
|
||||
d="M3347 1383 c-4 -3 -7 -78 -7 -165 l0 -158 315 0 315 0 -2 163 -3 162 -306 3 c-168 1 -308 -1 -312 -5z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="dropdown-container">
|
||||
<select name="date-options" id="date-options">
|
||||
<option value="dd-mm-yyyy">Day, Month, Year</option>
|
||||
<option value="yyyy-mm-dd">Year, Month, Day</option>
|
||||
<option value="mm-dd-yyyy-h-mm">
|
||||
Month, Day, Year, Hours, Minutes
|
||||
</option>
|
||||
</select>
|
||||
<div class="select-icon">
|
||||
<svg
|
||||
class="icon"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="25"
|
||||
height="35"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<rect x="0" fill="none" width="24" height="24" />
|
||||
|
||||
<g>
|
||||
<path d="M7 10l5 5 5-5" />
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="current-date"></p>
|
||||
</main>
|
||||
|
||||
<script src="./script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--dark-grey: #0a0a23;
|
||||
--white: #ffffff;
|
||||
--yellow: #f1be32;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--white);
|
||||
background-color: var(--dark-grey);
|
||||
}
|
||||
|
||||
.title-container {
|
||||
margin: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
margin: auto;
|
||||
width: 150px;
|
||||
height: 10px;
|
||||
background-color: var(--yellow);
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 50%;
|
||||
margin: 40px auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
select {
|
||||
display: block;
|
||||
margin: 20px auto 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
background-color: var(--white);
|
||||
border: none;
|
||||
color: var(--dark-grey);
|
||||
appearance: none;
|
||||
padding: 10px;
|
||||
padding-right: 38px;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
transition: color 0.3s ease, background-color 0.3s ease,
|
||||
border-bottom-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 30px;
|
||||
height: 36px;
|
||||
pointer-events: none;
|
||||
padding-left: 5px;
|
||||
transition: background-color 0.3s ease, border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon svg.icon {
|
||||
transition: fill 0.3s ease;
|
||||
fill: var(--dark-grey);
|
||||
}
|
||||
|
||||
#current-date {
|
||||
font-size: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 375px) {
|
||||
.title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
const currentDateParagraph = document.getElementById("current-date");
|
||||
const dateOptionsSelectElement = document.getElementById("date-options");
|
||||
|
||||
const date = new Date();
|
||||
const day = date.getDate();
|
||||
const month = date.getMonth() + 1;
|
||||
const year = date.getFullYear();
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
const formattedDate = `${day}-${month}-${year}`;
|
||||
currentDateParagraph.textContent = formattedDate;
|
||||
|
||||
--fcc-editable-region--
|
||||
const exampleSentence = "selur pmaCedoCeerf".split("").reverse();
|
||||
console.log(exampleSentence);
|
||||
--fcc-editable-region--
|
||||
dateOptionsSelectElement.addEventListener("change", () => {
|
||||
switch (dateOptionsSelectElement.value) {
|
||||
case "yyyy-mm-dd":
|
||||
currentDateParagraph.textContent = formattedDate
|
||||
}
|
||||
});
|
||||
```
|
||||
@ -0,0 +1,258 @@
|
||||
---
|
||||
id: 66074af5d2b4f373cb140d6a
|
||||
title: Step 22
|
||||
challengeType: 0
|
||||
dashedName: step-22
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
Now that you have a better understanding on how to work with the `split`, `reverse`, and `join` methods, you can delete your `exampleSentence` variable and console statement.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should not have a `exampleSentence` variable in your code.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /const\s+exampleSentence\s*=\s*['"]selur pmaCedoCeerf['"]\s*\.split\(['"]['"]\)\s*\.reverse\(\)\s*\.join\(['"]['"]\)/);
|
||||
```
|
||||
|
||||
You should not have a `console.log` statement in your code.
|
||||
|
||||
```js
|
||||
assert.notMatch(code, /console\.log\(exampleSentence\)/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Learn the Date Object by Building a Date Formatter</title>
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="title-container">
|
||||
<h1 class="title">Today's Date</h1>
|
||||
|
||||
<svg
|
||||
class="date-svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
version="1.0"
|
||||
width="512.000000pt"
|
||||
height="512.000000pt"
|
||||
viewBox="0 0 512.000000 512.000000"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
<g
|
||||
transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)"
|
||||
fill="#fff"
|
||||
stroke="none"
|
||||
>
|
||||
<path
|
||||
d="M1145 4777 c-71 -24 -120 -54 -164 -102 -59 -64 -83 -124 -89 -216 l-4 -77 -147 -3 c-142 -4 -149 -5 -213 -37 -81 -40 -149 -111 -177 -188 -21 -54 -21 -64 -21 -1789 0 -1725 0 -1735 21 -1789 28 -77 96 -148 177 -188 l67 -33 1950 0 1950 0 67 33 c74 36 133 96 170 170 l23 47 0 1760 0 1760 -23 47 c-37 74 -96 134 -169 170 -63 31 -71 32 -213 36 l-148 4 -4 77 c-8 133 -82 242 -200 297 -54 25 -75 29 -148 29 -94 -1 -151 -20 -220 -75 -75 -59 -130 -181 -130 -287 l0 -43 -954 0 -954 0 -7 74 c-12 137 -89 251 -201 303 -66 30 -179 39 -239 20z m209 -164 c23 -16 52 -49 66 -73 l25 -45 0 -365 0 -365 -28 -47 c-30 -52 -88 -92 -149 -103 -54 -10 -137 17 -175 57 -65 69 -64 60 -61 471 l3 373 27 41 c17 26 45 50 80 68 71 35 151 31 212 -12z m2594 11 c41 -20 59 -37 82 -78 l30 -51 0 -360 c0 -329 -2 -364 -19 -401 -36 -79 -137 -133 -222 -119 -57 10 -125 58 -151 107 -23 42 -23 50 -26 388 -3 377 -1 403 51 465 62 76 162 95 255 49z m537 -2717 l0 -1239 -24 -19 c-23 -19 -67 -19 -1916 -19 -1849 0 -1893 0 -1916 19 l-24 19 -3 1241 -2 1241 1942 -2 1943 -3 0 -1238z"
|
||||
/>
|
||||
<path
|
||||
d="M1112 2493 l3 -158 318 -3 317 -2 0 160 0 160 -320 0 -321 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 2490 l0 -160 315 0 315 0 0 160 0 160 -315 0 -315 0 0 -160z"
|
||||
/>
|
||||
<path
|
||||
d="M3342 2493 l3 -158 310 0 310 0 3 158 3 157 -316 0 -316 0 3 -157z"
|
||||
/>
|
||||
<path
|
||||
d="M1110 1855 l0 -155 320 0 320 0 0 155 0 155 -320 0 -320 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M3340 1855 l0 -155 315 0 315 0 0 155 0 155 -315 0 -315 0 0 -155z"
|
||||
/>
|
||||
<path
|
||||
d="M1117 1383 c-4 -3 -7 -78 -7 -165 l0 -158 320 0 320 0 0 165 0 165 -313 0 c-173 0 -317 -3 -320 -7z"
|
||||
/>
|
||||
<path
|
||||
d="M2230 1225 l0 -165 315 0 315 0 0 165 0 165 -315 0 -315 0 0 -165z"
|
||||
/>
|
||||
<path
|
||||
d="M3347 1383 c-4 -3 -7 -78 -7 -165 l0 -158 315 0 315 0 -2 163 -3 162 -306 3 c-168 1 -308 -1 -312 -5z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="dropdown-container">
|
||||
<select name="date-options" id="date-options">
|
||||
<option value="dd-mm-yyyy">Day, Month, Year</option>
|
||||
<option value="yyyy-mm-dd">Year, Month, Day</option>
|
||||
<option value="mm-dd-yyyy-h-mm">
|
||||
Month, Day, Year, Hours, Minutes
|
||||
</option>
|
||||
</select>
|
||||
<div class="select-icon">
|
||||
<svg
|
||||
class="icon"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="25"
|
||||
height="35"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<rect x="0" fill="none" width="24" height="24" />
|
||||
|
||||
<g>
|
||||
<path d="M7 10l5 5 5-5" />
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="current-date"></p>
|
||||
</main>
|
||||
|
||||
<script src="./script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
:root {
|
||||
--dark-grey: #0a0a23;
|
||||
--white: #ffffff;
|
||||
--yellow: #f1be32;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--white);
|
||||
background-color: var(--dark-grey);
|
||||
}
|
||||
|
||||
.title-container {
|
||||
margin: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
margin: auto;
|
||||
width: 150px;
|
||||
height: 10px;
|
||||
background-color: var(--yellow);
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 50%;
|
||||
margin: 40px auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
select {
|
||||
display: block;
|
||||
margin: 20px auto 0;
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
background-color: var(--white);
|
||||
border: none;
|
||||
color: var(--dark-grey);
|
||||
appearance: none;
|
||||
padding: 10px;
|
||||
padding-right: 38px;
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
transition: color 0.3s ease, background-color 0.3s ease,
|
||||
border-bottom-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
width: 30px;
|
||||
height: 36px;
|
||||
pointer-events: none;
|
||||
padding-left: 5px;
|
||||
transition: background-color 0.3s ease, border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.select-icon svg.icon {
|
||||
transition: fill 0.3s ease;
|
||||
fill: var(--dark-grey);
|
||||
}
|
||||
|
||||
#current-date {
|
||||
font-size: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (max-width: 375px) {
|
||||
.title {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.dropdown-container {
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.date-svg {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
const currentDateParagraph = document.getElementById("current-date");
|
||||
const dateOptionsSelectElement = document.getElementById("date-options");
|
||||
|
||||
const date = new Date();
|
||||
const day = date.getDate();
|
||||
const month = date.getMonth() + 1;
|
||||
const year = date.getFullYear();
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
const formattedDate = `${day}-${month}-${year}`;
|
||||
currentDateParagraph.textContent = formattedDate;
|
||||
|
||||
--fcc-editable-region--
|
||||
const exampleSentence = "selur pmaCedoCeerf".split("").reverse().join("");
|
||||
console.log(exampleSentence);
|
||||
--fcc-editable-region--
|
||||
dateOptionsSelectElement.addEventListener("change", () => {
|
||||
switch (dateOptionsSelectElement.value) {
|
||||
case "yyyy-mm-dd":
|
||||
currentDateParagraph.textContent = formattedDate
|
||||
}
|
||||
});
|
||||
```
|
||||
Loading…
Reference in New Issue
Block a user