freeCodeCamp/curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-...

128 lines
4.6 KiB
Markdown
Raw Normal View History

---
id: 587d778c367417b2b2512aa9
title: Standardize Times with the HTML5 datetime Attribute
challengeType: 0
videoUrl: 'https://scrimba.com/c/cmzMgtz'
forumTopicId: 301025
---
## Description
<section id='description'>
Continuing with the date theme, HTML5 also introduced the <code>time</code> element along with a <code>datetime</code> attribute to standardize times. This is an inline element that can wrap a date or time on a page. A valid format of that date is held by the <code>datetime</code> attribute. This is the value accessed by assistive devices. It helps avoid confusion by stating a standardized version of a time, even if it's written in an informal or colloquial manner in the text.
Here's an example:
<code>&lt;p&gt;Master Camper Cat officiated the cage match between Goro and Scorpion &lt;time datetime=&quot;2013-02-13&quot;&gt;last Wednesday&lt;/time&gt;, which ended in a draw.&lt;/p&gt;</code>
</section>
## Instructions
<section id='instructions'>
Camper Cat's Mortal Kombat survey results are in! Wrap a <code>time</code> tag around the text "Thursday, September 15&lt;sup&gt;th&lt;/sup&gt;" and add a <code>datetime</code> attribute to it set to "2016-09-15".
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: Your code should have a <code>p</code> element which includes the text <code>Thank you to everyone for responding to Master Camper Cat's survey.</code> and include a <code>time</code> element.
fixed testString to disallow any extra characters from passing. Also … (#35987) * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md Co-Authored-By: Stevo99 <Sfailla1983@gmail.com> * fixed test so it won't pass if datetime attr is left blank * fixed test so it will not pass if datetime attribute is left empty * fixed error in testString where test would pass if user runs test right away * added tear-down div to make test code look cleaner * fixed merge conflict. added tear-down div to make code look cleaner * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md improvement to test case where element should have closing tag. Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fixed conflict in git * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
2019-06-28 22:49:00 +00:00
testString: assert(timeElement.length);
- text: Your added <code>time</code> tags should wrap around the text <code>Thursday, September 15&lt;sup&gt;th&lt;/sup&gt;</code>.
fixed testString to disallow any extra characters from passing. Also … (#35987) * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md Co-Authored-By: Stevo99 <Sfailla1983@gmail.com> * fixed test so it won't pass if datetime attr is left blank * fixed test so it will not pass if datetime attribute is left empty * fixed error in testString where test would pass if user runs test right away * added tear-down div to make test code look cleaner * fixed merge conflict. added tear-down div to make code look cleaner * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md improvement to test case where element should have closing tag. Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fixed conflict in git * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
2019-06-28 22:49:00 +00:00
testString: assert(timeElement.length && $(timeElement).html().trim() === "Thursday, September 15<sup>th</sup>");
- text: Your added <code>time</code> tag should have a <code>datetime</code> attribute that is not empty.
testString: assert(datetimeAttr && datetimeAttr.length);
- text: Your added <code>datetime</code> attribute should be set to a value of <code>2016-09-15</code>.
fixed testString to disallow any extra characters from passing. Also … (#35987) * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md Co-Authored-By: Stevo99 <Sfailla1983@gmail.com> * fixed test so it won't pass if datetime attr is left blank * fixed test so it will not pass if datetime attribute is left empty * fixed error in testString where test would pass if user runs test right away * added tear-down div to make test code look cleaner * fixed merge conflict. added tear-down div to make code look cleaner * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md improvement to test case where element should have closing tag. Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fixed conflict in git * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
2019-06-28 22:49:00 +00:00
testString: assert(datetimeAttr === "2016-09-15");
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
```html
<body>
<header>
<h1>Tournaments</h1>
</header>
<article>
<h2>Mortal Kombat Tournament Survey Results</h2>
<!-- Only change code below this line -->
<p>Thank you to everyone for responding to Master Camper Cat's survey. The best day to host the vaunted Mortal Kombat tournament is Thursday, September 15<sup>th</sup>. May the best ninja win!</p>
<!-- Only change code above this line -->
<section>
<h3>Comments:</h3>
<article>
<p>Posted by: Sub-Zero on <time datetime="2016-08-13T20:01Z">August 13<sup>th</sup></time></p>
<p>Johnny Cage better be there, I'll finish him!</p>
</article>
<article>
<p>Posted by: Doge on <time datetime="2016-08-15T08:12Z">August 15<sup>th</sup></time></p>
<p>Wow, much combat, so mortal.</p>
</article>
<article>
<p>Posted by: The Grim Reaper on <time datetime="2016-08-16T00:00Z">August 16<sup>th</sup></time></p>
<p>Looks like I'll be busy that day.</p>
</article>
</section>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
</div>
fixed testString to disallow any extra characters from passing. Also … (#35987) * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md Co-Authored-By: Stevo99 <Sfailla1983@gmail.com> * fixed test so it won't pass if datetime attr is left blank * fixed test so it will not pass if datetime attribute is left empty * fixed error in testString where test would pass if user runs test right away * added tear-down div to make test code look cleaner * fixed merge conflict. added tear-down div to make code look cleaner * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md improvement to test case where element should have closing tag. Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fixed conflict in git * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
2019-06-28 22:49:00 +00:00
<div id='html-teardown'>
fixed testString to disallow any extra characters from passing. Also … (#35987) * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md Co-Authored-By: Stevo99 <Sfailla1983@gmail.com> * fixed test so it won't pass if datetime attr is left blank * fixed test so it will not pass if datetime attribute is left empty * fixed error in testString where test would pass if user runs test right away * added tear-down div to make test code look cleaner * fixed merge conflict. added tear-down div to make code look cleaner * fixed testString to disallow any extra characters from passing. Also changed markup in testString and text * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md improvement to test case where element should have closing tag. Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fixed conflict in git * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Update curriculum/challenges/english/01-responsive-web-design/applied-accessibility/standardize-times-with-the-html5-datetime-attribute.english.md removed unnecessary test Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
2019-06-28 22:49:00 +00:00
```html
<script>
const pElement = $("article > p")
.filter((_, elem) => $(elem).text().includes("Thank you to everyone for responding to Master Camper Cat's survey."));
const timeElement = pElement[0] ? $(pElement[0]).find("time") : null;
const datetimeAttr = $(timeElement).attr("datetime");
</script>
```
</div>
</section>
## Solution
<section id='solution'>
```html
<body>
<header>
<h1>Tournaments</h1>
</header>
<article>
<h2>Mortal Kombat Tournament Survey Results</h2>
<p>Thank you to everyone for responding to Master Camper Cat's survey. The best day to host the vaunted Mortal Kombat tournament is <time datetime="2016-09-15">Thursday, September 15<sup>th</sup></time>. May the best ninja win!</p>
<section>
<h3>Comments:</h3>
<article>
<p>Posted by: Sub-Zero on <time datetime="2016-08-13T20:01Z">August 13<sup>th</sup></time></p>
<p>Johnny Cage better be there, I'll finish him!</p>
</article>
<article>
<p>Posted by: Doge on <time datetime="2016-08-15T08:12Z">August 15<sup>th</sup></time></p>
<p>Wow, much combat, so mortal.</p>
</article>
<article>
<p>Posted by: The Grim Reaper on <time datetime="2016-08-16T00:00Z">August 16<sup>th</sup></time></p>
<p>Looks like I'll be busy that day.</p>
</article>
</section>
</article>
<footer>&copy; 2018 Camper Cat</footer>
</body>
```
</section>