diff --git a/challenges/01-responsive-web-design/applied-accessibility.json b/challenges/01-responsive-web-design/applied-accessibility.json
index 467b9c07d5..de273e6bb9 100644
--- a/challenges/01-responsive-web-design/applied-accessibility.json
+++ b/challenges/01-responsive-web-design/applied-accessibility.json
@@ -54,7 +54,7 @@
"<img src="importantLogo.jpeg" alt="Company logo">
",
"People with visual impairments rely on screen readers to convert web content to an audio interface. They won't get information if it's only presented visually. For images, screen readers can access the alt
attribute and read its contents to deliver key information.",
"Good alt
text is short but descriptive, and meant to briefly convey the meaning of the image. You should always include an alt
attribute on your image. Per HTML5 specification, this is now considered mandatory.",
- "
alt
attribute in the img
tag, that explains Camper Cat is doing karate. (The image src
doesn't link to an actual file, so you should see the alt
text in the display.)"
],
"challengeSeed": [
@@ -95,7 +95,7 @@
"<img src="visualDecoration.jpeg" alt="">
",
"Background images usually fall under the 'decorative' label as well. However, they are typically applied with CSS rules, and therefore not part of the markup screen readers process.",
"Notealt
text, since it helps search engines catalog the content of the image.",
- "alt
attribute to the img
tag and set it to an empty string. (Note that the image src
doesn't link to an actual file - don't worry that there are no swords showing in the display.)"
],
"challengeSeed": [
@@ -149,7 +149,7 @@
"Headings with equal (or higher) rank start new implied sections, headings with lower rank start subsections of the previous one.",
"As an example, a page with an h2
element followed by several subsections labeled with h4
tags would confuse a screen reader user. With six choices, it's tempting to use a tag because it looks better in a browser, but you can use CSS to edit the relative sizing.",
"One final point, each page should always have one (and only one) h1
element, which is the main subject of your content. This and the other headings are used in part by search engines to understand the topic of the page.",
- "h5
tags to the proper heading level to indicate they are subsections of the h2
ones."
],
"challengeSeed": [
@@ -205,7 +205,7 @@
"By default, a browser renders these elements similarly to the humble div
. However, using them where appropriate gives additional meaning in your markup. The tag name alone can indicate the type of information it contains, which adds semantic meaning to that content. Assistive technologies can access this information to provide better page summary or navigation options to their users.",
"The main
element is used to wrap (you guessed it) the main content, and there should be only one per page. It's meant to surround the information that's related to the central topic of your page. It's not meant to include items that repeat across pages, like navigation links or banners.",
"The main
tag also has an embedded landmark feature that assistive technology can use to quickly navigate to the main content. If you've ever seen a \"Jump to Main Content\" link at the top of a page, using a main tag automatically gives assistive devices that functionality.",
- "main
tags between the header
and footer
(covered in other challenges). Keep the main
tags empty for now."
],
"challengeSeed": [
@@ -253,7 +253,7 @@
"Remember that folks using assistive technologies rely on organized, semantically meaningful markup to better understand your work.",
"Note about section
and div
section
element is also new with HTML5, and has a slightly different semantic meaning than article
. An articles
is for standalone content, and a section
is for grouping thematically related content. They can be used within each other, as needed. For example, if a book is the article
, then each chapter is a section
. When there's no relationship between groups of content, then use a div
.",
"<div> - blocks content", - "
<section> - blocks related content
<article> - blocks independent, self-contained content
article
tags to wrap the posts on his blog page, but he forgot to use them around the top one. Change the div
tag to use an article
tag instead."
],
"challengeSeed": [
@@ -313,7 +313,7 @@
"The next HTML5 element that adds semantic meaning and improves accessibility is the header
tag. It's used to wrap introductory information or navigation links for its parent tag, and works well around content that's repeated at the top on multiple pages.",
"Header
shares the embedded landmark feature you saw with main
, allowing assistive technologies to quickly navigate to that content.",
"NoteHeader
is meant for use in the body
tag of your HTML document. This is different than the head
element, which contains the page's title, meta information, etc.",
- "div
that currently contains the h1
to a header
tag instead."
],
"challengeSeed": [
@@ -377,7 +377,7 @@
"description": [
"The nav
element is another HTML5 item with the embedded landmark feature for easy screen reader navigation. This tag is meant to wrap around the main navigation links in your page.",
"If there are repeated site links at the bottom of the page, it isn't necessary to markup those with a nav
tag as well. Using a footer
(covered in the next challenge) is sufficient.",
- "div
. Change the div
to a nav
tag to improve the accessibility on his page."
],
"challengeSeed": [
@@ -446,7 +446,7 @@
"title": "Make Screen Reader Navigation Easier with the Footer Landmark",
"description": [
"Similar to header
and nav
, the footer
element has a built-in landmark feature that allows assistive devices to quickly navigate to it. It's primarily used to contain copyright information or links to related documents that usually sit at the bottom of a page.",
- "div
he used to wrap his copyright information at the bottom of the page to a footer
element."
],
"challengeSeed": [
@@ -521,7 +521,7 @@
"Here's an example:",
"<audio id="meowClip" controls>", "Note
<source src="audio/meow.mp3" type="audio/mpeg" />
<source src="audio/meow.ogg" type="audio/ogg" />
</audio>
audio
element after the p
. Include the controls
attribute. Then place a source
tag inside the audio
tags with the src
attribute set to \"https://s3.amazonaws.com/freecodecamp/screen-reader.mp3\" and type
attribute set to \"audio/mpeg\"."
],
"challengeSeed": [
@@ -576,7 +576,7 @@
"For data visualizations like charts, the caption can be used to briefly note the trends or conclusions for users with visual impairments. Another challenge covers how to move a table version of the chart's data off-screen (using CSS) for screen reader users.",
"Here's an example - note that the figcaption
goes inside the figure
tags and can be combined with other elements:",
"<figure>", - "
<img src="roundhouseDestruction.jpeg" alt="Photo of Camper Cat executing a roundhouse kick">
<br>
<figcaption>
Master Camper Cat demonstrates proper form of a roundhouse kick.
</figcaption>
</figure>
div
tag he used to a figure
tag, and the p
tag that surrounds the caption to a figcaption
tag."
],
"challengeSeed": [
@@ -660,7 +660,7 @@
"The label
tag wraps the text for a specific form control item, usually the name or label for a choice. This ties meaning to the item and makes the form more readable. The for
attribute on a label
tag explicitly associates that label
with the form control and is used by screen readers.",
"The value of the for
attribute must be the same as the value of the id
attribute of the form control. Here's an example:",
"<form>", - "
<label for="name">Name:</label>
<input type="text" id="name" name="name">
</form>
for
attribute on the email label
that matches the id
on its input
field."
],
"challengeSeed": [
@@ -733,7 +733,7 @@
"The fieldset
wrapper and legend
tag are not necessary when the choices are self-explanatory, like a gender selection. Using a label
with the for
attribute for each radio button is sufficient.",
"Here's an example:",
"<form>", - "
<fieldset>
<legend>Choose one of these three items:</legend>
<input id="one" type="radio" name="items" value="one">
<label for="one">Choice One</label><br>
<input id="two" type="radio" name="items" value="two">
<label for="two">Choice Two</label><br>
<input id="three" type="radio" name="items" value="three">
<label for="three">Choice Three</label>
</fieldset>
</form>
for
attributes for each choice. Go Camper Cat! However, his code still needs some help. Change the div tag surrounding the radio buttons to a fieldset tag, and change the p tag inside it to a legend."
],
"challengeSeed": [
@@ -819,7 +819,7 @@
"For older browsers, the type will default to text
, so it helps to show users the expected date format in the label or as placeholder text just in case.",
"Here's an example:",
"<label for="input1">Enter a date (MM-DD-YYYY):</label>", - "
<input type="date" id="input1" name="input1">
input
tag with a type
attribute of \"date\", an id
attribute of \"pickdate\", and a name
attribute of \"date\"."
],
"challengeSeed": [
@@ -883,7 +883,7 @@
"Continuing with the date theme, HTML5 also introduced the time
element along with a datetime
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 datetime
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:",
"<p>Master Camper Cat officiated the cage match between Goro and Scorpion <time datetime="2013-02-13">last Wednesday</time>, which ended in a draw.</p>
",
- "time
tag around the text \"Thursday, September 15<sup>th</sup>\" and add a datetime
attribute to it set to \"2016-09-15\"."
],
"challengeSeed": [
@@ -960,7 +960,7 @@
"display: none;
or visibility: hidden;
hides content for everyone, including screen reader userswidth: 0px; height: 0px;
removes that element from the flow of your document, meaning screen readers will ignore itsr-only
class, but the CSS rules aren't filled in yet. Give the position
an absolute value, the left
a -10000px value, and the width
and height
both 1px values."
],
"challengeSeed": [
@@ -1084,7 +1084,7 @@
"description": [
"Low contrast between the foreground and background colors can make text difficult to read. Sufficient contrast improves the readability of your content, but what exactly does \"sufficient\" mean?",
"The Web Content Accessibility Guidelines (WCAG) recommend at least a 4.5 to 1 contrast ratio for normal text. The ratio is calculated by comparing the relative luminance values of two colors. This ranges from 1:1 for the same color, or no contrast, to 21:1 for white against black, the strongest contrast. There are many contrast checking tools available online that calculate this ratio for you.",
- "color
of the text from the current gray (#D3D3D3
) to a darker gray (#636363
) to improve the contrast ratio to 6:1."
],
"challengeSeed": [
@@ -1142,7 +1142,7 @@
"Previous challenges covered having text alternatives to address the first issue. The last challenge introduced contrast checking tools to help with the second. The WCAG-recommended contrast ratio of 4.5:1 applies for color use as well as gray-scale combinations.",
"Colorblind users have trouble distinguishing some colors from others - usually in hue but sometimes lightness as well. You may recall the contrast ratio is calculated using the relative luminance (or lightness) values of the foreground and background colors.",
"In practice, the 4.5:1 ratio can be reached by darkening the darker color and lightening the lighter one with the aid of a color contrast checker. Darker colors on the color wheel are considered to be blues, violets, magentas, and reds, whereas lighter colors are oranges, yellows, greens, and blue-greens.",
- "background-color
with maroon text color
has a 2.5:1 contrast ratio. You can easily adjust the lightness of the colors since he declared them using the CSS hsl()
property (which stands for hue, saturation, lightness) by changing the third argument. Increase the background-color
lightness value from 35% to 55%, and decrease the color
lightness value from 20% to 15%. This improves the contrast to 5.9:1."
],
"challengeSeed": [
@@ -1199,7 +1199,7 @@
"There are various forms of colorblindness. These can range from a reduced sensitivity to a certain wavelength of light to the inability to see color at all. The most common form is a reduced sensitivity to detect greens.",
"For example, if two similar green colors are the foreground and background color of your content, a colorblind user may not be able to distinguish them. Close colors can be thought of as neighbors on the color wheel, and those combinations should be avoided when conveying important information.",
"Note#FFFF33
) background-color
and the green (#33FF33
) text color
are neighboring hues on the color wheel and virtually indistinguishable for some colorblind users. (Their similar lightness also fails the contrast ratio check). Change the text color
to a dark blue (#003366
) to solve both problems."
],
"challengeSeed": [
@@ -1252,7 +1252,7 @@
"description": [
"Screen reader users have different options for what type of content their device reads. This includes skipping to (or over) landmark elements, jumping to the main content, or getting a page summary from the headings. Another option is to only hear the links available on a page.",
"Screen readers do this by reading the link text, or what's between the anchor (a
) tags. Having a list of \"click here\" or \"read more\" links isn't helpful. Instead, you should use brief but descriptive text within the a
tags to provide more meaning for these users.",
- "a
) tags so they wrap around the text \"information about batteries\" instead of \"Click here\"."
],
"challengeSeed": [
@@ -1300,7 +1300,7 @@
"HTML5 allows this attribute to be used on any element, but it's particularly useful when it's used with interactive ones. This includes links, buttons, and form controls.",
"Here's an example:",
"<button accesskey="b">Important Button</button>
",
- "accesskey
attribute to both links and set the first one to \"g\" (for Garfield) and the second one to \"c\" (for Chuck Norris)."
],
"challengeSeed": [
@@ -1364,7 +1364,7 @@
"Certain elements, such as links and form controls, automatically receive keyboard focus when a user tabs through a page. It's in the same order as the elements come in the HTML source markup. This same functionality can be given to other elements, such as div
, span
, and p
, by placing a tabindex=\"0\"
attribute on them. Here's an example:",
"<div tabindex="0">I need keyboard focus!</div>
",
"Notetabindex
value (typically -1) indicates that an element is focusable, but is not reachable by the keyboard. This method is generally used to bring focus to content programmatically (like when a div
used for a pop-up window is activated), and is beyond the scope of these challenges.",
- "tabindex
attribute to the p
tag and set its value to \"0\". Bonus - using tabindex
also enables the CSS pseudo-class :focus
to work on the p
tag."
],
"challengeSeed": [
@@ -1453,7 +1453,7 @@
"Here's an example:",
"<div tabindex="1">I get keyboard focus, and I get it first!</div>
",
"<div tabindex="2">I get keyboard focus, and I get it second!</div>
",
- "input
and submit input
form controls to be the first two items in the tab order. Add a tabindex
attribute set to \"1\" to the search input
, and a tabindex
attribute set to \"2\" to the submit input
."
],
"challengeSeed": [
diff --git a/challenges/01-responsive-web-design/applied-visual-design.json b/challenges/01-responsive-web-design/applied-visual-design.json
index 8fc9e892e0..f2d5e9d226 100644
--- a/challenges/01-responsive-web-design/applied-visual-design.json
+++ b/challenges/01-responsive-web-design/applied-visual-design.json
@@ -40,7 +40,7 @@
"description": [
"This section of the curriculum focuses on Applied Visual Design. The first group of challenges build on the given card layout to show a number of core principles.",
"Text is often a large part of web content. CSS has several options for how to align it with the text-align
property.",
- "h4
tag's text, which says \"Google\", to the center. Then justify the paragraph tag which contains information about how Google was founded. Finally, align the two anchor tags to the left by using the links
class selector.",
"Notewidth
property in CSS. Values can be given in relative length units (such as em), absolute length units (such as px), or as a percentage of its containing parent element. Here's an example that changes the width of an image to 220px:",
"img {", - "
width: 220px;
}
width
property to the entire card and set it to an absolute value of 245px. Use the fullCard
class to select the element."
],
"challengeSeed": [
@@ -184,7 +184,7 @@
"description": [
"You can specify the height of an element using the height
property in CSS, similar to the width
property. Here's an example that changes the height of an image to 20px:",
"img {", - "
height: 20px;
}
height
property to the h4
tag and set it to 40px."
],
"challengeSeed": [
@@ -256,7 +256,7 @@
"description": [
"This challenge changes the layout of the links by stacking them to look more like a list.",
"To keep everything balanced, you can make sure every element's width and height makes sense in that context.",
- "height
of the h4
tag to 25px to make the card more compact and a little cleaner."
],
"challengeSeed": [
@@ -330,7 +330,7 @@
"title": "Use the Strong Tag to Make Text Bold",
"description": [
"To make text bold, you can use the strong
tag. This is often used to draw attention to text and symbolize that it is important. With the strong
tag, the browser applies the CSS of font-weight: bold;
to the element.",
- "strong
tag around the entire h4
element and its contents."
],
"challengeSeed": [
@@ -405,7 +405,7 @@
"title": "Use the u Tag to Underline Text",
"description": [
"To underline text, you can use the u
tag. This is often used to signify that a section of text is important, or something to remember. With the u
tag, the browser applies the CSS of text-decoration: underline;
to the element.",
- "u
tag around the two anchor tags. It should not include the parent div
that has the class of cardLinks
.",
"Noteu
tag when it could be confused for a link. Anchor tags also have a default underlined formatting."
],
@@ -482,7 +482,7 @@
"title": "Use the em Tag to Italicize Text",
"description": [
"To emphasize text, you can use the em
tag. This displays text as italicized, as the browser applies the CSS of font-style: italic;
to the element.",
- "em
tag around the paragraph tag to give it emphasis."
],
"challengeSeed": [
@@ -559,7 +559,7 @@
"title": "Use the del Tag to Strikethrough Text",
"description": [
"To strikethrough text, which is when a horizontal line cuts across the characters, you can use the del
tag. It shows that a section of text is no longer valid. With the del
tag, the browser applies the CSS of text-decoration: line-through;
to the element.",
- "del
tag around \"Google\" inside the h4
tag and then add the word Alphabet beside it, which should not have the strikethrough formatting."
],
"challengeSeed": [
@@ -637,7 +637,7 @@
"title": "Create a Horizontal Line Using the hr Element",
"description": [
"You can use the hr
tag to add a horizontal line across the width of its containing element. This can be used to define a change in topic or to visually separate groups of content.",
- "hr
tag underneath the h4
which contains the card title.",
"Notehr
is a self-closing tag, and therefore doesn't need a separate closing tag."
],
@@ -719,7 +719,7 @@
"rgba stands for:", "The rgb values can range from 0 to 255. The alpha value can range from 1, which is fully opaque or a solid color, to 0, which is fully transparent or clear.
r = red
g = green
b = blue
a = alpha/level of opacity
rgba()
is great to use in this case, as it allows you to adjust the opacity. This means you don't have to completely block out the background.",
"You'll use background-color: rgba(45, 45, 45, 0.1)
for this challenge. It produces a dark gray color that is nearly transparent given the low opacity value of 0.1.",
- "background-color
of the h4
element to the given rgba()
value.",
"Also for the h4
, remove the height
property and add padding
of 10px."
],
@@ -801,7 +801,7 @@
"title": "Adjust the Size of a Header Versus a Paragraph Tag",
"description": [
"The font size of header tags (h1
through h6
) should generally be larger than the font size of paragraph tags. This makes it easier for the user to visually understand the layout and level of importance of everything on the page. You use the font-size
property to adjust the size of the text in an element.",
- "font-size
of the h4
tag to 27 pixels."
],
"challengeSeed": [
@@ -883,7 +883,7 @@
"The box-shadow
property takes values for offset-x
(how far to push the shadow horizontally from the element), offset-y
(how far to push the shadow vertically from the element), blur-radius
, spread-radius
and a color value, in that order. The blur-radius
and spread-radius
values are optional.",
"Here's an example of the CSS to create multiple shadows with some blur, at mostly-transparent black colors:",
"box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);", - "
box-shadow
on the card. The element now has an id of thumbnail
, use this selector to place the shadows for the hover state."
],
"challengeSeed": [
@@ -970,7 +970,7 @@
"The opacity
property in CSS is used to adjust the opacity, or conversely, the transparency for an item.",
"A value of 1 is opaque, which isn't transparent at all.", "The value given will apply to the entire element, whether that's an image with some transparency, or the foreground and background colors for a block of text.", - "
A value of 0.5 is half see-through.
A value of 0 is completely transparent.
opacity
of the anchor tags to 0.7 using links
class to select them."
],
"challengeSeed": [
@@ -1054,7 +1054,7 @@
"description": [
"The text-transform
property in CSS is used to set text to uppercase.",
"Noteh4
tag to be uppercase using the text-transform
property."
],
"challengeSeed": [
@@ -1149,7 +1149,7 @@
"<link href=\"https://fonts.googleapis.com/css?family=Open+Sans\" rel=\"stylesheet\">
",
"Once the link is in place, the font is available to include in your CSS by using the pattern font-family: 'FONT', FAMILY_NAME;
.",
"In this example, \"FONT\" would be 'Open Sans' and \"FAMILY_NAME\" would be sans-serif. The quotes around 'Open Sans' are required because it has a space in its name. Also, capitalization of the font name matters.",
- "font-family
of the body to \"Open Sans\"."
],
"challengeSeed": [
@@ -1238,7 +1238,7 @@
"title": "Set the Font-size for Multiple Heading Elements",
"description": [
"The font-size
property is used to specify how large the text is in a given element. This rule can be used for multiple elements to create visual consistency of text on a page. In this challenge, you'll set the values for all h1
through h6
tags to balance the heading sizes.",
- "font-size
of the h1
tag to 68px.font-size
of the h2
tag to 52px.font-size
of each heading tag in the last challenge, here you'll adjust the font-weight
.",
"The font-weight
property sets how thick or thin characters are in a section of text.",
- "font-weight
of the h1
tag to 800.font-weight
of the h2
tag to 600.font-size
property in CSS is not limited to headings, it can be applied to any element containing text.",
- "font-size
property for the paragraph to 16px to make it more visible."
],
"challengeSeed": [
@@ -1425,7 +1425,7 @@
"title": "Set the Line-height of Paragraphs",
"description": [
"CSS offers the line-height
property to change the height of each line in a block of text. As the name suggests, it changes the amount of vertical space that each line of text gets.",
- "line-height
property to the p
tag and set it to 25px."
],
"challengeSeed": [
@@ -1470,7 +1470,7 @@
"title": "Adjust the Color of an Anchor Tag",
"description": [
"You can adjust the text color of any text in an element with the color
property.",
- "color
property of the anchor (a
) tag to #000
(black)."
],
"challengeSeed": [
@@ -1512,7 +1512,7 @@
"title": "Adjust the Hover State of an Anchor Tag",
"description": [
"Following from the previous challenge, the styling of the anchor tag can be changed for its hover state using the :hover
pseudo-class selector.",
- "a
tag's CSS so when the user hovers over it, the color
is blue and the underline is removed.",
"Notetext-decoration
property set to none."
],
@@ -1563,7 +1563,8 @@
"p {", "Changing an element's position to relative does not remove it from the normal flow - other elements around it still behave as if that item were in its default position.", "Note
position: relative;
bottom: 10px;
}
position
of the h2
to relative
, and use a CSS offset to move it 15 pixels away from the top
of where it sits in the normal flow. Notice there is no impact on the positions of the surrounding h1 and p elements."
],
"challengeSeed": [
@@ -1611,7 +1612,7 @@
"title": "Move a Relatively Positioned Element with CSS Offsets",
"description": [
"The CSS offsets of top
or bottom
, and left
or right
tell the browser how far to offset an item relative to where it would sit in the normal flow of the document. This can be slightly confusing, because you're offsetting an element away from a given spot, which effectively moves it towards the opposite direction. As you saw in the last challenge, using the top offset moved the h2 downwards. Likewise, using a left offset effectively moves an item to the right.",
- "h2
15 pixels to the right and 10 pixels up."
],
"challengeSeed": [
@@ -1663,7 +1664,7 @@
"description": [
"The next option for the CSS position
property is absolute
, which locks the element in place relative to its parent container. Unlike the relative
position, this removes the element from the normal flow of the document, so surrounding items ignore it. The CSS offset properties (top or bottom and left or right) are used to adjust the position.",
"One nuance with absolute positioning is that it will be locked relative to its closest positioned ancestor. If you forget to add a position rule to the parent item, (this is typically done using position: relative;
), the browser will keep looking up the chain and ultimately default to the body tag.",
- "#searchbar
element to the top-right of its section
parent by declaring its position
as absolute
. Give it top
and right
offsets of 0 pixels each."
],
"challengeSeed": [
@@ -1722,7 +1723,7 @@
"description": [
"The next layout scheme that CSS offers is the fixed
position, which is a type of absolute positioning that locks an element relative to the browser window. Similar to absolute positioning, it's used with the CSS offset properties and also removes the element from the normal flow of the document. Other items no longer \"realize\" where it is positioned, which may require some layout adjustments elsewhere.",
"One key difference from the absolute
position is that the element won't move when the user scrolls.",
- "navbar
. Change its position
to fixed
, and offset it 0 pixels from the top
and 0 pixels from the left
. Notice the (lack of) impact to the h1
position, it hasn't been pushed down to accommodate the navigation bar and would need to be adjusted separately."
],
"challengeSeed": [
@@ -1792,7 +1793,7 @@
"title": "Push Elements Left or Right with the Float Property",
"description": [
"The next positioning tool does not actually use position
, but sets the float
property of an element. Floating elements are removed from the normal flow of a document and pushed to either the left
or right
of their containing parent element. It's commonly used with the width
property to specify how much horizontal space the floated element requires.",
- "section
and aside
elements next to each other. Give the #left
item a float
of left
and the #right
item a float
of right
."
],
"challengeSeed": [
@@ -1858,7 +1859,7 @@
"title": "Change the Position of Overlapping Elements with the Z-index Property",
"description": [
"When elements are positioned to overlap, the element coming later in the HTML markup will, by default, appear on the top of the other elements. However, the z-index
property can specify the order of how elements are stacked on top of one another. It must be an integer (i.e. a whole number and not a decimal), and higher values for the z-index
property of an element move it higher in the stack than those with lower values.",
- "z-index
property to the element with the class name of first
(the red rectangle) and set it to a value of 2 so it covers the other element (blue rectangle)."
],
"challengeSeed": [
@@ -1918,7 +1919,7 @@
"description": [
"Another positioning technique is to center a block element horizontally. One way to do this is to set its margin
to a value of auto.",
"This method works for images, too. Images are inline elements by default, but can be changed to block elements when you set the display
property to block.",
- "div
on the page by adding a margin
property with a value of auto."
],
"challengeSeed": [
@@ -1968,7 +1969,7 @@
"red (#FF0000) and cyan (#00FFFF)", "There are many color picking tools available online that have an option to find the complement of a color.", "Note
green (#00FF00) and magenta (#FF00FF)
blue (#0000FF) and yellow (#FFFF00)
background-color
property of the blue
and yellow
classes to their respective colors. Notice how the colors look different next to each other than they do compared against the white background."
],
"challengeSeed": [
@@ -2027,7 +2028,7 @@
"There are various methods of selecting different colors that result in a harmonious combination in design. One example that can use tertiary colors is called the split-complementary color scheme. It starts with a base color, then pairs it with the two colors that are adjacent to its complement. The three colors provide strong visual contrast in a design, but is more subtle than using two complementary colors.",
"Here are three colors using the split-complement scheme:",
"cyan (#00FFFF)", - "
orange (#FF7D00)
raspberry (#FF007D)
background-color
property of the orange
, cyan
, and raspberry
classes to their respective colors. Make sure to use the hex codes because the orange and raspberry in the example above are not browser-recognized color names."
],
"challengeSeed": [
@@ -2087,7 +2088,7 @@
"title": "Adjusting the Color of Various Elements to Complementary Colors",
"description": [
"The complementary colors challenge showed that opposite colors on the color wheel can make each other appear more vibrant when placed side-by-side. However, the strong visual contrast can be jarring if it's overused on a website, and can sometimes make text harder to read if it's placed on a complementary-colored background. In practice, one of the colors is usually dominant and the complement is used to bring visual attention to certain content on the page.",
- "#09A7A1
) as the dominant color, and its orange (#FF790E
) complement to visually highlight the sign-up buttons. Change the background-color
of both the header
and footer
from black to the teal color. Then change the h2
text color
to teal as well. Finally, change the background-color
of the button
to the orange color."
],
"challengeSeed": [
@@ -2169,7 +2170,7 @@
"Lightness is the amount of white or black in a color. A percentage is given ranging from 0% (black) to 100% (white), where 50% is the normal color.",
"Here are a few examples of using hsl()
with fully-saturated, normal lightness colors:",
"/* Red */", - "
hsl(0, 100%, 50%) (Red can also have a hue of 360)
/* Yellow */
hsl(60, 100%, 50%)
/* Green */
hsl(120, 100%, 50%)
/* Cyan */
hsl(180, 100%, 50%)
/* Blue */
hsl(240, 100%, 50%)
/* Magenta */
hsl(300, 100%, 50%)
background-color
of each div
element based on the class names (green
, cyan
, or blue
) using hsl()
. All three should have full saturation and normal lightness."
],
"challengeSeed": [
@@ -2233,7 +2234,7 @@
"title": "Adjust the Tone of a Color",
"description": [
"The hsl()
option in CSS also makes it easy to adjust the tone of a color. Mixing white with a pure hue creates a tint of that color, and adding black will make a shade. Alternatively, a tone is produced by adding gray or by both tinting and shading. Recall that the 's' and 'l' of hsl()
stand for saturation and lightness, respectively. The saturation percent changes the amount of gray and the lightness percent determines how much white or black is in the color. This is useful when you have a base hue you like, but need different variations of it.",
- "background-color
from the header
element. Starting with that color as a base, add a background-color
to the nav
element so it uses the same teal hue, but has 80% saturation and 25% lightness values to change its tone and shade."
],
"challengeSeed": [
@@ -2308,7 +2309,7 @@
"The fist argument specifies the direction from which color transition starts - it can be stated as a degree, where 90deg makes a vertical gradient and 45deg is angled like a backslash. The following arguments specify the order of colors used in the gradient.",
"Example:",
"background: linear-gradient(90deg, red, yellow, rgb(204, 204, 255));
",
- "linear-gradient()
for the div
element's background
, and set it from a direction of 35 degrees to change the color from #CCFFFF
to #FFCCCC
."
],
"challengeSeed": [
@@ -2362,7 +2363,7 @@
"For this example, it helps to think about the color stops as pairs where every two colors blend together.",
"0px [yellow -- blend -- blue] 40px [green -- blend -- red] 80px
",
"If every two color stop values are the same color, the blending isn't noticeable because it's between the same color, followed by a hard transition to the next color, so you end up with stripes.",
- "repeating-linear-gradient()
to use a gradient angle of 45deg
, then set the first two color stops to yellow
, and finally the second two color stops to black
."
],
"challengeSeed": [
@@ -2422,7 +2423,7 @@
"title": "Create Texture by Adding a Subtle Pattern as a Background Image",
"description": [
"One way to add texture and interest to a background and have it stand out more is to add a subtle pattern. The key is balance, as you don't want the background to stand out too much, and take away from the foreground. The background
property supports the url()
function in order to link to an image of the chosen texture or pattern. The link address is wrapped in quotes inside the parentheses.",
- "https://i.imgur.com/MJAkxbh.png
, set the background
of the whole page with the body
selector."
],
"challengeSeed": [
@@ -2466,7 +2467,7 @@
"description": [
"To change the scale of an element, CSS has the transform
property, along with its scale()
function. The following code example doubles the size of all the paragraph elements on the page:",
"p {", - "
transform:scale(2);
}
ball2
to 1.5 times its original size."
],
"challengeSeed": [
@@ -2531,7 +2532,7 @@
"The transform
property has a verity of functions that lets you scale, move, rotate, skew, etc., your elements. When used with pseudo-classes such as :hover
that specify a certain state of an element, the transform
property can easily add interactivity to your elements.",
"Here's an example to scale the paragraph elements to 2.1 times their original size when a user hovers over them:",
"p:hover {", - "
transform: scale(2.1);}
}
hover
state of the div
and use the transform
property to scale the div
element to 1.1 times its original size when a user hovers over it."
],
"challengeSeed": [
@@ -2588,7 +2589,7 @@
"The next function of the transform
property is skewX()
, which skews the selected element along its X (horizontal) axis by a given degree.",
"The following code skews the paragraph element by -32 degrees along the X axis.",
"p {", - "
transform: skewX(-32deg);
}
bottom
by 24 degrees along the X axis by using the transform
property."
],
"challengeSeed": [
@@ -2644,7 +2645,7 @@
"title": "Use the CSS Transform Property SkewY",
"description": [
"Given that the skewX()
function skews the selected element along the X axis by a given degree, it is no surprise that the skewY()
property skews an element along the Y (vertical) axis.",
- "top
-10 degrees along the Y axis by using the transform
property."
],
"challengeSeed": [
@@ -2702,7 +2703,7 @@
"You will create a round, transparent object with a crisp shadow that is slightly offset to the side - the shadow is actually going to be the moon shape you see.",
"In order to create a round object, the border-radius
property should be set to a value of 50%.",
"You may recall from an earlier challenge that the box-shadow
property takes values for offset-x
, offset-y
, blur-radius
, spread-radius
and a color value in that order. The blur-radius
and spread-radius
values are optional.",
- "background-color
to transparent, then set the border-radius
property to 50% to make the circular shape. Finally, change the box-shadow
property to set the offset-x
to 25px, the offset-y
to 10px, blur-radius
to 0, spread-radius
to 0, and color to blue."
],
"challengeSeed": [
@@ -2762,7 +2763,7 @@
".heart:before {", "For the
content: \"\";
background-color: yellow;
border-radius: 25%;
position: absolute;
height: 50px;
width: 70px;
top: -50px;
left: 5px;
}
:before
and :after
selectors to function properly, they must have a defined content
property. It usually has content such as a photo or text. When the :before
and :after
selectors add shapes, the content
property is still required, but it's set to an empty string.",
"In the above example, the element with the class of heart
has a :before
selector that produces a yellow rectangle with height
and width
of 50px and 70px, respectively. This rectangle has round corners due to its 25% border radius and is positioned absolutely at 5px from the left
and 50px above the top
of the element.",
- "heart:after
selector, change the background-color
to pink and the border-radius
to 50%.",
"Next, target the element with the class heart
(just heart
) and fill in the transform
property. Use the rotate()
function with -45 degrees. (rotate()
works the same way that skewX()
and skewY()
do).",
"Finally, in the heart:before
selector, set its content
property to an empty string."
@@ -2843,7 +2844,7 @@
"@keyframes
is how to specify exactly what happens within the animation over the duration. This is done by giving CSS properties for specific \"frames\" during the animation, with percentages ranging from 0% to 100%. If you compare this to a movie, the CSS properties for 0% is how the element displays in the opening scene. The CSS properties for 100% is how the element appears at the end, right before the credits roll. Then CSS applies the magic to transition the element over the given duration to act out the scene. Here's an example to illustrate the usage of @keyframes
and the animate properties:",
"#anim {", "For the element with the
animation-name: colorful;
animation-duration: 3s;
}
@keyframes colorful {
0% {
background-color: blue;
}
100% {
background-color: yellow;
}
}
anim
id, the code snippet above sets the animation-name
to colorful
and sets the animation-duration
to 3 seconds. Then the @keyframes
rule links to the animation properties with the name colorful
. It sets the color to blue at the beginning of the animation (0%) which will transition to yellow by the end of the animation (100%). You aren't limited to only beginning-end transitions, you can set properties for the element for any percentage between 0% and 100%.",
- "rect
, by setting the animation-name
to rainbow and the animation-duration
to 4 seconds. Next, declare a @keyframes
rule, and set the background-color
at the beginning of the animation (0%
) to blue, the middle of the animation (50%
) to green, and the end of the animation (100%
) to yellow."
],
"challengeSeed": [
@@ -2907,7 +2908,7 @@
"You can use CSS @keyframes
to change the color of a button in its hover state.",
"Here's an example of changing the height of an image on hover:",
"<style>", - "
img:hover {
animation-name: width;
animation-duration: 4s;
}
@keyframes width {
100% {
width: 40px;
}
}
</style>
<img src="https://bit.ly/smallgooglelogo" alt="Google's Logo" />
@keyframes
to change the background-color
of the button
element so it becomes #4791d0
when a user hovers over it. The @keyframes
rule should only have an entry for 100%
."
],
"challengeSeed": [
@@ -2961,7 +2962,7 @@
"When elements have a specified position
, such as fixed
or relative
, the CSS offset properties right
, left
, top
, and bottom
can be used in animation rules to create movement.",
"As shown in the example below, you can push the item downwards then upwards by setting the top
property of the 50%
keyframe to 50px, but having it set to 0px for the first (0%
) and the last (100%
) keyframe.",
"@keyframes rainbow {", - "
0% {
background-color: blue;
top: 0px;
}
50% {
background-color: green;
top: 50px;
}
100% {
background-color: yellow;
top: 0px;
}
}
div
animation. Using the left
offset property, add to the @keyframes
rule so rainbow starts at 0 pixels at 0%
, moves to 25 pixels at 50%
, and ends at -25 pixels at 100%
."
],
"challengeSeed": [
@@ -3035,7 +3036,7 @@
"description": [
"For this challenge, you'll change the opacity
of an animated element so it gradually fades as it reaches the right side of the screen.",
"In the displayed animation, the round element with the gradient background moves to the right by the 50% mark of the animation per the @keyframes
rule.",
- "ball
and add the opacity
property set to 0.1 at 50%
so the element fades as it moves to the right."
],
"challengeSeed": [
@@ -3101,7 +3102,7 @@
"The previous challenges covered how to use some of the animation properties and the @keyframes
rule. Another animation property is the animation-iteration-count
, which allows you to control how many times you would like to loop through the animation. Here's an example:",
"animation-iteration-count: 3;
",
"The above animation will stop after running 3 times, but it's possible to make the animation run continuously by setting that value to infinite.",
- "animation-iteration-count
property to infinite."
],
"challengeSeed": [
@@ -3171,7 +3172,7 @@
"description": [
"Here's one more continuous animation example with the animation-iteration-count
property that uses the heart you designed in a previous challenge.",
"The one second long heartbeat animation consists of two animated pieces. The heart
elements (including the :before
and :after
pieces) are animated to change size using the transform
property, and the background div
is animated to change its color using the background
property.",
- "animation-iteration-count
property for both the back
class and the heart
class and setting the value to infinite. The heart:before
and heart:after
selectors do not need any animation properties."
],
"challengeSeed": [
@@ -3278,7 +3279,7 @@
"description": [
"There are a variety of ways to alter the animation rates of similarly animated elements. So far, this has been achieved by applying an animation-iteration-count
property and setting @keyframes
rules.",
"To illustrate, the animation on the right consists of two \"stars\" that each decrease in size and opacity at the 20% mark in the @keyframes
rule, which creates the twinkle animation. You can change the @keyframes
rule for one of the elements so the stars twinkle at different rates.",
- "star-1
by changing its @keyframes
rule to 50%."
],
"challengeSeed": [
@@ -3369,7 +3370,7 @@
"description": [
"In the previous challenge, you changed the animation rates for two similarly animated elements by altering their @keyframes
rules. You can achieve the same goal by manipulating the animation-duration
of multiple elements.",
"In the animation running in the code editor, there are three \"stars\" in the sky that twinkle at the same rate on a continuous loop. To make them twinkle at different rates, you can set the animation-duration
property to different values for each element.",
- "animation-duration
of the elements with the classes star-1
, star-2
, and star-3
to 1s, 0.9s, and 1.1s, respectively."
],
"challengeSeed": [
@@ -3461,7 +3462,7 @@
"description": [
"In CSS animations, the animation-timing-function
property controls how quickly an animated element changes over the duration of the animation. If the animation is a car moving from point A to point B in a given time (your animation-duration
), the animation-timing-function
says how the car accelerates and decelerates over the course of the drive.",
"There are a number of predefined keywords available for popular options. For example, the default value is linear
, which applies a constant animation speed throughout. Other options include ease-out
, which is quick in the beginning then slows down, or ease-in
, which is slow in the beginning, then speeds up at the end.",
- "ball1
and ball2
, add an animation-timing-function
property to each, and set #ball1
to linear
, and #ball2
to ease-out
. Notice the difference between how the elements move during the animation but end together, since they share the same animation-duration
of 2 seconds."
],
"challengeSeed": [
@@ -3541,7 +3542,7 @@
"The cubic-bezier
function consists of four main points that sit on this 1 by 1 grid: p0
, p1
, p2
, and p3
. p0
and p3
are set for you - they are the beginning and end points which are always located respectively at the origin (0, 0) and (1, 1). You set the x and y values for the other two points, and where you place them in the grid dictates the shape of the curve for the animation to follow. This is done in CSS by declaring the x and y values of the p1
and p2
\"anchor\" points in the form: (x1, y1, x2, y2)
. Pulling it all together, here's an example of a Bezier curve in CSS code:",
"animation-timing-function: cubic-bezier(0.25, 0.25, 0.75, 0.75);
",
"In the example above, the x and y values are equivalent for each point (x1 = 0.25 = y1 and x2 = 0.75 = y2), which if you remember from geometry class, results in a line that extends from the origin to point (1, 1). This animation is a linear change of an element during the length of an animation, and is the same as using the linear
keyword. In other words, it changes at a constant speed.",
- "ball1
, change the value of the animation-timing-function
property from linear
to its equivalent cubic-bezier
function value. Use the point values given in the example above."
],
"challengeSeed": [
@@ -3620,7 +3621,7 @@
"In general, changing the p1
and p2
anchor points drives the creation of different Bezier curves, which controls how the animation progresses through time. Here's an example of a Bezier curve using values to mimic the ease-out style:",
"animation-timing-function: cubic-bezier(0, 0, 0.58, 1);
",
"Remember that all cubic-bezier
functions start with p0
at (0, 0) and end with p3
at (1, 1). In this example, the curve moves faster through the Y axis (starts at 0, goes to p1
y value of 0, then goes to p2
y value of 1) than it moves through the X axis (0 to start, then 0 for p1
, up to 0.58 for p2
). As a result, the change in the animated element progresses faster than the time of the animation for that segment. Towards the end of the curve, the relationship between the change in x and y values reverses - the y value moves from 1 to 1 (no change), and the x values move from 0.58 to 1, making the animation changes progress slower compared to the animation duration.",
- "animation-timing-function
of the element with id of red
to a cubic-bezier
function with x1, y1, x2, y2 values set respectively to 0, 0, 0.58, 1. This will make both elements progress through the animation similarly."
],
"challengeSeed": [
@@ -3694,7 +3695,7 @@
"The following cubic Bezier curve simulates a juggling movement:",
"cubic-bezier(0.3, 0.4, 0.5, 1.6);
",
"Notice that the value of y2 is larger than 1. Although the cubic Bezier curve is mapped on an 1 by 1 coordinate system, and it can only accept x values from 0 to 1, the y value can be set to numbers larger than one. This results in a bouncing movement that is ideal for simulating the juggling ball.",
- "animation-timing-function
of the element with the id of green
to a cubic-bezier
function with x1, y1, x2, y2 values set respectively to 0.311, 0.441, 0.444, 1.649."
],
"challengeSeed": [
diff --git a/challenges/01-responsive-web-design/basic-css.json b/challenges/01-responsive-web-design/basic-css.json
index cad7004c73..eb4789763f 100644
--- a/challenges/01-responsive-web-design/basic-css.json
+++ b/challenges/01-responsive-web-design/basic-css.json
@@ -2059,7 +2059,7 @@
"The two main types of length units are absolute and relative. Absolute units tie to physical units of length. For example, in
and mm
refer to inches and millimeters, respectively. Absolute length units approximate the actual measurement on a screen, but there are some differences depending on a screen's resolution.",
"Relative units, such as em
or rem
, are relative to another length value. For example, em
is based on the size of an element's font. If you use it to set the font-size
property itself, it's relative to the parent's font-size
.",
"Notepadding
property to the element with class red-box
and set it to 1.5em
."
],
"challengeSeed": [
diff --git a/challenges/01-responsive-web-design/basic-html-and-html5.json b/challenges/01-responsive-web-design/basic-html-and-html5.json
index 68b7ac31a8..66d8db1239 100644
--- a/challenges/01-responsive-web-design/basic-html-and-html5.json
+++ b/challenges/01-responsive-web-design/basic-html-and-html5.json
@@ -56,7 +56,7 @@
"</h1>
",
"Note that the only difference between opening tags and closing tags is that closing tags have a slash after their opening angle bracket.",
"Each challenge has tests that you can run at any time by clicking the \"Run tests\" button. Once you get all tests passing (they change from red to green), you can go to the next coding challenge.",
- "h1
element's text to say \"Hello World\" instead of \"Hello\". Then click the \"Run tests\" button."
],
"challengeSeed": [
@@ -263,7 +263,7 @@
"These tags not only make your HTML easier to read, it also helps with Search Engine Optimization (SEO) and accessibility.",
"The main
HTML5 tag helps search engines and other developers find the main content of your page.",
"Notemain
tag."
],
"challengeSeed": [
@@ -719,7 +719,7 @@
"Next, you'll want to create a corresponding anchor link in the HTML where you want the internal link to take users. Instead of using the href
attribute, you'll use the name
attribute. Here's an example:",
"<h1>Contact</h1>", "Now when users click the \"Go to contact section\" link, they'll be taken to the section of the webpage with the anchor that has the
<a name=\"contact\"></a>
name
attribute \"contact\".",
- "href
attribute to \"#bottom\" and the anchor text from \"cat photos\" to \"Jump to Bottom\".",
"Then add an anchor link with a name
attribute set to \"bottom\" after the last paragraph.",
"Notehtml
tags. The opening <html>
goes directly below the <!DOCTYPE html>
line, and the closing </html>
goes at the end of the page.",
"Here's an example of the page structure:",
"<!DOCTYPE html>", - "
<html>
<!-- Your HTML code goes here -->
</html>
DOCTYPE
tag for HTML5 to the top of the blank HTML document in the code editor. Under it, add opening and closing html
tags, which wrap around an h1
element. The heading can include any text."
],
"challengeSeed": [
@@ -2321,7 +2321,7 @@
"Metadata elements, such as link
, meta
, title
, and style
, typically go inside the head
element.",
"Here's an example of a page's layout:",
"<!DOCTYPE html>", - "
<html>
<head>
<!-- metadata elements -->
</head>
<body>
<!-- page contents -->
</body>
</html>
head
and a body
. The head
element should only include the title
, and the body
element should only include the h1
and p
."
],
"challengeSeed": [
diff --git a/challenges/01-responsive-web-design/css-flexbox.json b/challenges/01-responsive-web-design/css-flexbox.json
index 04bc664511..fdb3ab0623 100644
--- a/challenges/01-responsive-web-design/css-flexbox.json
+++ b/challenges/01-responsive-web-design/css-flexbox.json
@@ -40,7 +40,7 @@
"description": [
"This section uses alternating challenge styles to show how to use CSS to position elements in a flexible way. First, a challenge will explain theory, then a practical challenge using a simple tweet component will apply the flexbox concept.",
"Placing the CSS property display: flex;
on an element allows you to use other flex properties to build a responsive page.",
- "display
to both #box-1
and #box-2
and set each to a value of flex."
],
"challengeSeed": [
@@ -102,7 +102,7 @@
"title": "Adding Flex Superpowers to the Tweet Embed",
"description": [
"To the right is the tweet embed that will be used as the practical example. Some of the elements would look better with a different layout. The last challenge demonstrated display: flex
. Here you'll add it to several components in the tweet embed to start adjusting their positioning.",
- "display: flex
to all of the following items - note that the selectors are already set up in the CSS:",
"header
, the header's .profile-name
, the header's .follow-btn
, the header's h3
and h4
, the footer
, and the footer's .stats
."
],
@@ -243,7 +243,7 @@
"description": [
"Adding display: flex
to an element turns it into a flex container. This makes it possible to align any children of that element into rows or columns. You do this by adding the flex-direction
property to the parent item and setting it to row or column. Creating a row will align the children horizontally, and creating a column will align the children vertically.",
"Noteflex-direction
property is row.",
- "flex-direction
to the #box-container
element, and give it a value of row."
],
"challengeSeed": [
@@ -309,7 +309,7 @@
"title": "Applying the Flex-direction Property to Create Rows in the Tweet Embed",
"description": [
"The header
and footer
in the tweet embed example have child items that could be arranged as rows using the flex-direction
property. This tells CSS to align the children horizontally.",
- "flex-direction
to both the header
and footer
and set the value to row."
],
"challengeSeed": [
@@ -445,7 +445,7 @@
"title": "Using the Flex-direction Property to Make a Column",
"description": [
"The last two challenges used the flex-direction
property set to row. This property can also create a column by vertically stacking the children of a flex container.",
- "flex-direction
to the #box-container
element, and give it a value of column."
],
"challengeSeed": [
@@ -511,7 +511,7 @@
"title": "Applying the Flex-direction Property to Create a Column in the Tweet Embed",
"description": [
"The tweet embed header
and footer
used the flex-direction
property earlier with a row value. Similarly, the items inside the .profile-name
element would work well stacked as a column.",
- "flex-direction
to the header's .profile-name
element and set the value to column."
],
"challengeSeed": [
@@ -652,7 +652,7 @@
"space-between
: aligns items to the center of the main axis, with extra space placed between the items. The first and last items are pushed to the very edge of the flex container. For example, in a row the first item is against the left side of the container, the last item is against the right side of the container, then the other items between them are spaced evenly.space-around
: similar to space-between
but the first and last items are not locked to the edges of the container, the space is distributed around all the itemsjustify-content
to the #box-container
element, and give it a value of center.",
"Bonusjustify-content
property in the code editor to see their differences. But note that a value of center is the only one that will pass this challenge."
],
@@ -721,7 +721,7 @@
"title": "Using the Justify-content Property in the Tweet Embed",
"description": [
"The last challenge showed an example of the justify-content
property. For the tweet embed, this property can be applied to align the items in the .profile-name
element.",
- "justify-content
to the header's .profile-name
element and set the value to any of the options from the last challenge."
],
"challengeSeed": [
@@ -864,7 +864,7 @@
"stretch
: stretch the items to fill the flex container. For example, rows items are stretched to fill the flex container top-to-bottom.baseline
: align items to their baselines. Baseline is a text concept, think of it as the line that the letters sit on.align-items
to the #box-container
element, and give it a value of center.",
"Bonusalign-items
property in the code editor to see their differences. But note that a value of center is the only one that will pass this challenge."
],
@@ -933,7 +933,7 @@
"title": "Using the Align-items Property in the Tweet Embed",
"description": [
"The last challenge introduced the align-items
property and gave an example. This property can be applied to a few tweet embed elements to align the flex items inside them.",
- "align-items
to the header's .follow-btn
element, the header's h3
, and the header's h4
. Set the value to center."
],
"challengeSeed": [
@@ -1077,7 +1077,7 @@
"wrap
: wraps items from left-to-right if they are in a row, or top-to-bottom if they are in a column.wrap-reverse
: wraps items from right-to-left if they are in a row, or bottom-to-top if they are in a column.flex-wrap
to the #box-container
element, and give it a value of wrap."
],
"challengeSeed": [
@@ -1171,7 +1171,7 @@
"So far, all the properties in the challenges apply to the flex container (the parent of the flex items). However, there are several useful properties for the flex items.",
"The first is the flex-shrink
property. When it's used, it allows an item to shrink if the flex container is too small. Items shrink when the width of the parent container is smaller than the combined widths of all the flex items within it.",
"The flex-shrink
property takes numbers as values. The higher the number, the more it will shrink compared to the other items in the container. For example, if one item has a flex-shrink
value of 1 and the other has a flex-shrink
value of 3, the one with the value of 3 will shrink three times as much as the other.",
- "flex-shrink
to both #box-1
and #box-2
. Give #box-1
a value of 1 and #box-2
a value of 2."
],
"challengeSeed": [
@@ -1241,7 +1241,7 @@
"description": [
"The opposite of flex-shrink
is the flex-grow
property. Recall that flex-shrink
controls the size of the items when the container shrinks. The flex-grow
property controls the size of items when the parent container expands.",
"Using a similar example from the last challenge, if one item has a flex-grow
value of 1 and the other has a flex-grow
value of 3, the one with the value of 3 will grow three times as much as the other.",
- "flex-grow
to both #box-1
and #box-2
. Give #box-1
a value of 1 and #box-2
a value of 2."
],
"challengeSeed": [
@@ -1311,7 +1311,7 @@
"description": [
"The previous example included flex-basis
to help demonstrate how the flex-grow
property works. The flex-basis
property specifies the initial size of the item before CSS makes adjustments with flex-shrink
or flex-grow
.",
"The units used by the flex-basis
property are the same as other size properties (px
, em
, %
, etc.). The value auto
sizes items based on the content.",
- "flex-basis
. Add the CSS property flex-basis
to both #box-1
and #box-2
. Give #box-1
a value of 10em and #box-2
a value of 20em."
],
"challengeSeed": [
@@ -1382,7 +1382,7 @@
"There is a shortcut available to set several flex properties at once. The flex-grow
, flex-shrink
, and flex-basis
properties can all be set together by using the flex
property.",
"For example, flex: 1 0 10px;
will set the item to flex-grow: 1;
, flex-shrink: 0;
, and flex-basis: 10px;
.",
"The default property settings are flex: 0 1 auto;
.",
- "flex
to both #box-1
and #box-2
. Give #box-1
the values so its flex-grow
is 2, its flex-shrink
is 2, and its flex-basis
is 150px. Give #box-2
the values so its flex-grow
is 1, its flex-shrink
is 1, and its flex-basis
is 150px.",
"These values will cause #box-1
to be twice the size of #box-2
when the container is greater than 300px and half the size of #box-2 when the container is less than 300px. 300px is the combined size of the flex-basis
values of the two boxes."
],
@@ -1451,7 +1451,7 @@
"title": "Using the Order Property to Rearrange Items",
"description": [
"The order
property is used to tell CSS the order of how flex items appear in the flex container. By default, items will appear in the same order they come in the source HTML. The property takes numbers as values, and negative numbers can be used.",
- "order
to both #box-1
and #box-2
. Give #box-1
a value of 2 and give #box-2
a value of 1."
],
"challengeSeed": [
@@ -1521,7 +1521,7 @@
"description": [
"The final property for flex items is align-self
. This property allows you to adjust each item's alignment individually, instead of setting them all at once. This is useful since other common adjustment techniques using the CSS properties float
, clear
, and vertical-align
do not work on flex items.",
"align-self
accepts the same values as align-items
and will override any value set by the align-items
property.",
- "align-self
to both #box-1
and #box-2
. Give #box-1
a value of center and give #box-2
a value of flex-end."
],
"challengeSeed": [
diff --git a/challenges/01-responsive-web-design/responsive-web-design.json b/challenges/01-responsive-web-design/responsive-web-design.json
index 83e3b3070a..120bd6030f 100644
--- a/challenges/01-responsive-web-design/responsive-web-design.json
+++ b/challenges/01-responsive-web-design/responsive-web-design.json
@@ -61,7 +61,7 @@
"Here's an example of a media query that returns the content when the device's width is smaller than 100px:",
"@media (max-width: 100px) { /* CSS Rules */ }
",
"Remember, the CSS inside the media query is applied only if the media type matches that of the device being used.",
- "p
tag has a font-size
of 10px when the device's height is smaller than 800px."
],
"challengeSeed": [
@@ -107,7 +107,7 @@
"You can use:",
"img {", "The
max-width: 100%;
display: block;
height: auto;
}
max-width
property of 100% scales the image to fit the width of its container, but the image won't stretch wider than its original width. Setting the display
property to block changes the image from an inline element (its default), to a block element on its own line. The height
property of auto keeps the original aspect ratio of the image.",
- "img
tag to make it responsive to the size of its container. It should display as a block-level element, it should fit the full width of its container without stretching, and it should keep its original aspect ratio."
],
"challengeSeed": [
@@ -152,7 +152,7 @@
"The simplest way to make your images appear \"retina\" (and optimize them for retina displays) is to define their width
and height
values as only half of what the original file is.",
"Here is an example of an image that is only using half of the original height and width:",
"<style>", - "
img { height: 250px; width: 250px; }
</style>
<img src="coolPic500x500" alt="A most excellent picture">
width
and height
of the img
tag to half of their original values. In this case, both the original height
and the original width
are 200px."
],
"challengeSeed": [
@@ -201,7 +201,7 @@
"vmin: 70vmin
would be 70% of the viewport's smaller dimension (height vs. width).vmax: 100vmax
would be 100% of the viewport's bigger dimension (height vs. width).width
of the h2
tag to 80% of the viewport's width and the width
of the paragraph as 75% of the viewport's smaller dimension."
],
"challengeSeed": [
diff --git a/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json b/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
index 235d83d81b..726a3506d8 100644
--- a/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/basic-javascript.json
@@ -15,7 +15,7 @@
"You can make a multi-line comment beginning with /*
and ending with */
:",
"/* This is a", "Best Practice
multi-line comment */
/*Voici un commentaire
sur plusieurs lignes */
",
"Conseils",
"Lorsque vous écrivez votre code, vous devriez ajouter régulièrement des commentaires pour clarifier l'objectif de certaines parties de votre code. De bons commentaires peuvent aider les autres et vous-même à mieux comprendre votre code.",
- "var ourName;", "creates a
variable
called ourName
. In JavaScript we end statements with semicolons.",
"Variable
names can be made up of numbers, letters, and $
or _
, but may not contain spaces or start with a number.",
- "var
keyword to create a variable called myName
.",
"HintourName
example if you get stuck."
],
@@ -117,7 +117,7 @@
"var notreNom
;",
"crée une variable
appelée notreNom
.On termine nos expressions avec un point virgule en JavaScript.",
"Le nom d'une variable
peut être composé de nombres, lettres et $
ou _
, mais ne peut contenir d'espaces ou commencer par un nombre.",
- "var
pour créer une variable appelée monNom
",
"ConseilnotreNom
si vous vous êtes bloqué."
]
@@ -134,7 +134,7 @@
"Assignment always goes from right to left. Everything to the right of the =
operator is resolved before the value is assigned to the variable to the left of the operator.",
"myVar = 5;", "Assigns
myNum = myVar;
5
to myVar
and then resolves myVar
to 5
again and assigns it to myNum
.",
- "7
to variable a
.",
"Assign the contents of a
to variable b
."
],
@@ -193,7 +193,7 @@
"It is common to initialize a variable to an initial value in the same line as it is declared.",
"var myVar = 0;
",
"Creates a new variable called myVar
and assigns it an initial value of 0
.",
- "a
with var
and initialize it to a value of 9
."
],
"releasedOn": "January 1, 2016",
@@ -233,7 +233,7 @@
"title": "Understanding Uninitialized Variables",
"description": [
"When JavaScript variables are declared, they have an initial value of undefined
. If you do a mathematical operation on an undefined
variable your result will be NaN
which means \"Not a Number\". If you concatenate a string with an undefined
variable, you will get a literal string of \"undefined\"
.",
- "a
, b
, and c
with 5
, 10
, and \"I am a\"
respectively so that they will not be undefined
."
],
"releasedOn": "January 1, 2016",
@@ -285,7 +285,7 @@
"Write variable names in Javascript in camelCase. In camelCase, multi-word variable names have the first word in lowercase and the first letter of each subsequent word is capitalized.",
"Examples:",
"var someVariable;", - "
var anotherVariableName;
var thisVariableNameIsTooLong;
Number
is a data type in JavaScript which represents numeric data.",
"Now let's try to add two numbers using JavaScript.",
"JavaScript uses the +
symbol as addition operation when placed between two numbers.",
- "",
"Example",
"myVar = 5 + 10; // assigned 15", - "", - "
0
so that sum will equal 20
."
],
"challengeSeed": [
@@ -380,7 +378,7 @@
"Example",
"myVar = 12 - 6; // assigned 6", "", - "
0
so the difference is 12
."
],
"challengeSeed": [
@@ -422,7 +420,7 @@
"Example",
"myVar = 13 * 13; // assigned 169", "", - "
0
so that product will equal 80
."
],
"challengeSeed": [
@@ -463,7 +461,7 @@
"Example",
"myVar = 16 / 2; // assigned 8", "", - "
0
so that the quotient
is equal to 2
."
],
"challengeSeed": [
@@ -503,7 +501,7 @@
"is the equivalent of",
"i = i + 1;
",
"Notei++;
, eliminating the need for the equal sign.",
- "++
operator on myVar
.",
"Hinti = i - 1;
",
"Notei--;
, eliminating the need for the equal sign.",
- "--
operator on myVar
."
],
"releasedOn": "January 1, 2016",
@@ -598,7 +596,7 @@
"description": [
"We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as floating point numbers or floats.",
"NotemyDecimal
and give it a decimal value with a fractional part (e.g. 5.7
)."
],
"challengeSeed": [
@@ -638,7 +636,7 @@
"description": [
"In JavaScript, you can also perform calculations with decimal numbers, just like whole numbers.",
"Let's multiply two decimals together to get their product.",
- "0.0
so that product will equal 5.0
."
],
"challengeSeed": [
@@ -675,7 +673,7 @@
"title": "Divide one Decimal by Another with JavaScript",
"description": [
"Now let's divide one decimal by another.",
- "0.0
so that quotient
will equal to 2.2
."
],
"challengeSeed": [
@@ -716,7 +714,7 @@
"Usage2
.",
"17 % 2 = 1 (17 is Odd)", "Note
48 % 2 = 0 (48 is Even)
remainder
equal to the remainder of 11
divided by 3
using the remainder (%
) operator."
],
"releasedOn": "January 1, 2016",
@@ -764,7 +762,7 @@
"to add 5
to myVar
. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step.",
"One such operator is the +=
operator.",
"var myVar = 1;", - "
myVar += 5;
console.log(myVar); // Returns 6
a
, b
, and c
to use the +=
operator."
],
"releasedOn": "January 1, 2016",
@@ -818,7 +816,7 @@
"myVar = myVar - 5;
",
"will subtract 5
from myVar
. This can be rewritten as: ",
"myVar -= 5;
",
- "a
, b
, and c
to use the -=
operator."
],
"releasedOn": "January 1, 2016",
@@ -872,7 +870,7 @@
"myVar = myVar * 5;
",
"will multiply myVar
by 5
. This can be rewritten as: ",
"myVar *= 5;
",
- "a
, b
, and c
to use the *=
operator."
],
"releasedOn": "January 1, 2016",
@@ -926,7 +924,7 @@
"myVar = myVar / 5;
",
"Will divide myVar
by 5
. This can be rewritten as: ",
"myVar /= 5;
",
- "a
, b
, and c
to use the /=
operator."
],
"releasedOn": "January 1, 2016",
@@ -1025,7 +1023,7 @@
"Previously we have used the code",
"var myName = \"your name\";
",
"\"your name\"
is called a string literal. It is a string because it is a series of zero or more characters enclosed in single or double quotes.",
- "string
variables: myFirstName
and myLastName
and assign them the values of your first and last name, respectively."
],
"challengeSeed": [
@@ -1068,7 +1066,7 @@
"var sampleStr = \"Alan said, \\\"Peter is learning JavaScript\\\".\";
",
"This signals to JavaScript that the following quote is not the end of the string, but should instead appear inside the string. So if you were to print this to the console, you would get:",
"Alan said, \"Peter is learning JavaScript\".
",
- "myStr
variable so that if you were to print it to the console, you would see:",
"I am a \"double quoted\" string inside \"double quotes\".
"
],
@@ -1119,7 +1117,7 @@
"The value in using one or the other has to do with the need to escape quotes of the same type. Unless they are escaped, you cannot have more than one pair of whichever quote type begins a string.",
"If you have a string with many double quotes, this can be difficult to read and write. Instead, use single quotes:",
"'This string has \"double quotes\" in it. And \"probably\" lots of them.'
",
- "Code | Output |
---|---|
\\' | single quote |
\\\" | double quote |
\\\\ | backslash |
\\n | newline |
\\r | carriage return |
\\t | tab |
\\b | backspace |
\\f | form feed |
myStr
using escape sequences.",
"FirstLine", "You will need to use escape sequences to insert special characters correctly. You will also need to follow the spacing as it looks above, with no spaces between escape sequences or words.", @@ -1211,7 +1209,7 @@ "Example", "
\\SecondLine
ThirdLine
'My name is Alan,' + ' I concatenate.'", "Note
myStr
from the strings \"This is the start. \"
and \"This is the end.\"
using the +
operator."
],
"releasedOn": "January 1, 2016",
@@ -1265,7 +1263,7 @@
"description": [
"We can also use the +=
operator to concatenate a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines.",
"NotemyStr
over several lines by concatenating these two strings:\"This is the first sentence. \"
and \"This is the second sentence.\"
using the +=
operator."
],
"releasedOn": "January 1, 2016",
@@ -1315,7 +1313,7 @@
"title": "Constructing Strings with Variables",
"description": [
"Sometimes you will need to build a string, Mad Libs style. By using the concatenation operator (+
), you can insert one or more variables into a string you're building.",
- "myName
to a string equal to your name and build myStr
with myName
between the strings \"My name is \"
and \" and I am well!\"
"
],
"releasedOn": "January 1, 2016",
@@ -1371,7 +1369,7 @@
"title": "Appending Variables to Strings",
"description": [
"Just as we can build a string over multiple lines out of string literals, we can also append variables to a string using the plus equals (+=
) operator.",
- "someAdjective
and append it to myStr
using the +=
operator."
],
"releasedOn": "January 1, 2016",
@@ -1430,7 +1428,7 @@
"You can find the length of a String
value by writing .length
after the string variable or string literal.",
"\"Alan Peter\".length; // 10
",
"For example, if we created a variable var firstName = \"Charles\"
, we could find out how long the string \"Charles\"
is by using the firstName.length
property.",
- ".length
property to count the number of characters in the lastName
variable and assign it to lastNameLength
."
],
"challengeSeed": [
@@ -1480,7 +1478,7 @@
"Bracket notation
is a way to get a character at a specific index
within a string.",
"Most modern programming languages, like JavaScript, don't start counting at 1 like humans do. They start at 0. This is referred to as Zero-based indexing.",
"For example, the character at index 0 in the word \"Charles\" is \"C\". So if var firstName = \"Charles\"
, you can get the value of the first letter of the string by using firstName[0]
.",
- "lastName
variable and assign it to firstLetterOfLastName
.",
"HintfirstLetterOfFirstName
variable declaration if you get stuck."
],
@@ -1534,7 +1532,7 @@
"var myStr = \"Bob\";", "cannot change the value of
myStr[0] = \"J\";
myStr
to \"Job\", because the contents of myStr
cannot be altered. Note that this does not mean that myStr
cannot be changed, just that the individual characters of a string literal cannot be changed. The only way to change myStr
would be to assign it with a new string, like this:",
"var myStr = \"Bob\";", - "
myStr = \"Job\";
myStr
to achieve the desired effect that is intended by myStr[0] = \"H\" ;
."
],
"releasedOn": "January 1, 2016",
@@ -1581,7 +1579,7 @@
"description": [
"You can also use bracket notation to get the character at other positions within a string.",
"Remember that computers start counting at 0
, so the first character is actually the zeroth character.",
- "thirdLetterOfLastName
to equal the third letter of the lastName
variable using bracket notation.",
"HintsecondLetterOfFirstName
variable declaration if you get stuck."
],
@@ -1629,7 +1627,7 @@
"description": [
"In order to get the last letter of a string, you can subtract one from the string's length.",
"For example, if var firstName = \"Charles\"
, you can get the value of the last letter of the string by using firstName[firstName.length - 1]
.",
- "lastName
variable.",
"HintlastLetterOfFirstName
variable declaration if you get stuck."
],
@@ -1677,7 +1675,7 @@
"description": [
"You can use the same principle we just used to retrieve the last character in a string to retrieve the Nth-to-last character.",
"For example, you can get the value of the third-to-last letter of the var firstName = \"Charles\"
string by using firstName[firstName.length - 3]
",
- "lastName
string.",
"HintthirdToLastLetterOfFirstName
variable declaration if you get stuck."
],
@@ -1776,7 +1774,7 @@
"With JavaScript array
variables, we can store several pieces of data in one place.",
"You start an array declaration with an opening square bracket, end it with a closing square bracket, and put a comma between each entry, like this: ",
"var sandwich = [\"peanut butter\", \"jelly\", \"bread\"]
.",
- "myArray
so that it contains both a string
and a number
(in that order).",
"Hint[[\"Bulls\", 23], [\"White Sox\", 45]]
. This is also called a Multi-dimensional Array.",
- "myArray
."
],
"challengeSeed": [
@@ -1861,7 +1859,7 @@
"Example",
"var array = [1,2,3];", "Note
array[0]; // equals 1
var data = array[1]; // equals 2
array [0]
. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.",
- "myData
and set it to equal the first value of myArray
using bracket notation."
],
"challengeSeed": [
@@ -1911,7 +1909,7 @@
"Example",
"var ourArray = [3,2,1];", "Note
ourArray[0] = 1; // equals [1,2,1]
array [0]
. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.",
- "0
of myArray
to a value of 3
."
],
"challengeSeed": [
@@ -1960,7 +1958,7 @@
"Example",
"var arr = [", "Note
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[3]; // equals [[10,11,12], 13, 14]
arr[3][0]; // equals [10,11,12]
arr[3][0][1]; // equals 11
array [0][0]
and even this array [0] [0]
is not allowed. Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.",
- "myArray
such that myData
is equal to 8
."
],
"releasedOn": "January 1, 2016",
@@ -2004,7 +2002,7 @@
"An easy way to append data to the end of an array is via the push()
function.",
".push()
takes one or more parameters and \"pushes\" them onto the end of the array.",
"var arr = [1,2,3];", - "
arr.push(4);
// arr is now [1,2,3,4]
[\"dog\", 3]
onto the end of the myArray
variable."
],
"challengeSeed": [
@@ -2050,7 +2048,7 @@
".pop()
is used to \"pop\" a value off of the end of an array. We can store this \"popped off\" value by assigning it to a variable. In other words, .pop()
removes the last element from an array and returns that element.",
"Any type of entry can be \"popped\" off of an array - numbers, strings, even nested arrays.",
"var threeArr = [1, 4, 6];
var oneDown = threeArr.pop();
console.log(oneDown); // Returns 6
console.log(threeArr); // Returns [1, 4]
",
- ".pop()
function to remove the last item from myArray
, assigning the \"popped off\" value to removedFromMyArray
."
],
"challengeSeed": [
@@ -2099,7 +2097,7 @@
"description": [
"pop()
always removes the last element of an array. What if you want to remove the first?",
"That's where .shift()
comes in. It works just like .pop()
, except it removes the first element instead of the last.",
- ".shift()
function to remove the first item from myArray
, assigning the \"shifted off\" value to removedFromMyArray
."
],
"challengeSeed": [
@@ -2146,7 +2144,7 @@
"description": [
"Not only can you shift
elements off of the beginning of an array, you can also unshift
elements to the beginning of an array i.e. add elements in front of the array.",
".unshift()
works exactly like .push()
, but instead of adding the element at the end of the array, unshift()
adds the element at the beginning of the array.",
- "[\"Paul\",35]
to the beginning of the myArray
variable using unshift()
."
],
"challengeSeed": [
@@ -2263,7 +2261,7 @@
"You can call or invoke this function by using its name followed by parentheses, like this:",
"functionName();
",
"Each time the function is called it will print out the message \"Hello World\"
on the dev console. All of the code between the curly braces will be executed every time the function is called.",
- "reusableFunction
which prints \"Hi World\"
to the dev console.testFun
:",
"testFun(\"Hello\", \"World\");
",
"We have passed two arguments, \"Hello\"
and \"World\"
. Inside the function, param1
will equal \"Hello\" and param2
will equal \"World\". Note that you could call testFun
again with different arguments and the parameters would take on the value of the new arguments.",
- "functionWithArgs
that accepts two arguments and outputs their sum to the dev console.var
keyword are automatically created in the global
scope. This can create unintended consequences elsewhere in your code or when running a function again. You should always declare your variables with var
.",
- "var
, declare a global
variable myGlobal
outside of any function. Initialize it with a value of 10
.",
"Inside function fun1
, assign 5
to oopsGlobal
without using the var
keyword."
],
@@ -2511,7 +2509,7 @@
"Here is a function myTest
with a local variable called loc
.",
"function myTest() {", "
var loc = \"foo\";
console.log(loc);
}
myTest(); // logs \"foo\"
console.log(loc); // loc is not defined
loc
is not defined outside of the function.",
- "myVar
inside myLocalScope
. Run the tests and then follow the instructions commented out in the editor.",
"Hintvar someVar = \"Hat\";", "The function
function myFun() {
var someVar = \"Head\";
return someVar;
}
myFun
will return \"Head\"
because the local
version of the variable is present.",
- "myOutfit
to override the value of outerWear
with \"sweater\"
."
],
"releasedOn": "January 1, 2016",
@@ -2638,7 +2636,7 @@
"Example",
"function plusThree(num) {", "
return num + 3;
}
var answer = plusThree(5); // 8
plusThree
takes an argument for num
and returns a value equal to num + 3
.",
- "timesFive
that accepts one argument, multiplies it by 5
, and returns the new value."
],
"releasedOn": "January 1, 2016",
@@ -2688,7 +2686,7 @@
"Assume we have pre-defined a function sum
which adds two numbers together, then: ",
"ourSum = sum(5, 12);
",
"will call sum
function, which returns a value of 17
and assigns it to ourSum
variable.",
- "processArg
function with an argument of 7
and assign its return value to the variable processed
."
],
"releasedOn": "January 1, 2016",
@@ -2819,7 +2817,7 @@
"description": [
"Another data type is the Boolean. Booleans
may only be one of two values: true
or false
. They are basically little on-off switches, where true
is \"on\" and false
is \"off.\" These two states are mutually exclusive.",
"NoteBoolean
values are never written with quotes. The strings
\"true\"
and \"false\"
are not Boolean
and have no special meaning in JavaScript.",
- "welcomeToBooleans
function so that it returns true
instead of false
when the run button is clicked."
],
"challengeSeed": [
@@ -2867,7 +2865,7 @@
"Example",
"function test (myCondition) {", "When
if (myCondition) {
return \"It was true\";
}
return \"It was false\";
}
test(true); // returns \"It was true\"
test(false); // returns \"It was false\"
test
is called with a value of true
, the if
statement evaluates myCondition
to see if it is true
or not. Since it is true
, the function returns \"It was true\"
. When we call test
with a value of false
, myCondition
is not true
and the statement in the curly braces is not executed and the function returns \"It was false\"
.",
- "if
statement inside the function to return \"Yes, that was true\"
if the parameter wasThatTrue
is true
and return \"No, that was false\"
otherwise."
],
"challengeSeed": [
@@ -2934,7 +2932,7 @@
"If myVal
is equal to 10
, the equality operator returns true
, so the code in the curly braces will execute, and the function will return \"Equal\"
. Otherwise, the function will return \"Not Equal\"
.",
"In order for JavaScript to compare two different data types
(for example, numbers
and strings
), it must convert one type to another. Once it does, however, it can compare terms as follows:",
"1 == 1 // true", - "
1 == 2 // false
1 == '1' // true
\"3\" == 3 // true
equality operator
to the indicated line so that the function will return \"Equal\" when val
is equivalent to 12
"
],
"releasedOn": "January 1, 2016",
@@ -2985,7 +2983,7 @@
"Examples",
"3 === 3 // true", "In the second example,
3 === '3' // false
3
is a Number
type and '3'
is a String
type.",
- "if
statement so the function will return \"Equal\" when val
is strictly equal to 7
"
],
"releasedOn": "January 1, 2016",
@@ -3033,7 +3031,7 @@
"The inequality operator (!=
) is the opposite of the equality operator. It means \"Not Equal\" and returns false
where equality would return true
and vice versa. Like the equality operator, the inequality operator will convert data types of values while comparing.",
"Examples",
"1 != 2 // true", - "
1 != \"1\" // false
1 != '1' // false
1 != true // false
0 != false // false
!=
in the if
statement so that the function will return \"Not Equal\" when val
is not equivalent to 99
"
],
"releasedOn": "January 1, 2016",
@@ -3082,7 +3080,7 @@
"The strict inequality operator (!==
) is the logical opposite of the strict equality operator. It means \"Strictly Not Equal\" and returns false
where strict equality would return true
and vice versa. Strict inequality will not convert data types.",
"Examples",
"3 !== 3 // false", - "
3 !== '3' // true
4 !== 3 // true
strict inequality operator
to the if
statement so the function will return \"Not Equal\" when val
is not strictly equal to 17
"
],
"releasedOn": "January 1, 2016",
@@ -3139,7 +3137,7 @@
"Like the equality operator, greater than operator will convert data types of values while comparing.",
"Examples",
"5 > 3 // true", - "
7 > '3' // true
2 > 3 // false
'1' > 9 // false
greater than
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
@@ -3196,7 +3194,7 @@
"Like the equality operator, greater than or equal to
operator will convert data types while comparing.",
"Examples",
"6 >= 6 // true", - "
7 >= '3' // true
2 >= 3 // false
'7' >= 9 // false
greater than or equal to
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
@@ -3252,7 +3250,7 @@
"The less than operator (<
) compares the values of two numbers. If the number to the left is less than the number to the right, it returns true
. Otherwise, it returns false
. Like the equality operator, less than operator converts data types while comparing.",
"Examples",
"2 < 5 // true", - "
'3' < 7 // true
5 < 5 // false
3 < 2 // false
'8' < 4 // false
less than
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
@@ -3306,7 +3304,7 @@
"The less than or equal to
operator (<=
) compares the values of two numbers. If the number to the left is less than or equal the number to the right, it returns true
. If the number on the left is greater than the number on the right, it returns false
. Like the equality operator, less than or equal to
converts data types.",
"Examples",
"4 <= 5 // true", - "
'7' <= 7 // true
5 <= 5 // true
3 <= 2 // false
'8' <= 4 // false
less than or equal to
operator to the indicated lines so that the return statements make sense."
],
"releasedOn": "January 1, 2016",
@@ -3364,7 +3362,7 @@
"if (num > 5) {", "will only return \"Yes\" if
if (num < 10) {
return \"Yes\";
}
}
return \"No\";
num
is greater than 5
and less than 10
. The same logic can be written as:",
"if (num > 5 && num < 10) {", - "
return \"Yes\";
}
return \"No\";
\"Yes\"
if val
is less than or equal to 50
and greater than or equal to 25
. Otherwise, will return \"No\"
."
],
"releasedOn": "January 1, 2016",
@@ -3426,7 +3424,7 @@
"if (num > 10) {", "will return \"Yes\" only if
return \"No\";
}
if (num < 5) {
return \"No\";
}
return \"Yes\";
num
is between 5
and 10
(5 and 10 included). The same logic can be written as:",
"if (num > 10 || num < 5) {", - "
return \"No\";
}
return \"Yes\";
if
statements into one statement which returns \"Outside\"
if val
is not between 10
and 20
, inclusive. Otherwise, return \"Inside\"
."
],
"releasedOn": "January 1, 2016",
@@ -3487,7 +3485,7 @@
"description": [
"When a condition for an if
statement is true, the block of code following it is executed. What about when that condition is false? Normally nothing would happen. With an else
statement, an alternate block of code can be executed.",
"if (num > 10) {", - "
return \"Bigger than 10\";
} else {
return \"10 or Less\";
}
if
statements into a single if/else
statement."
],
"releasedOn": "January 1, 2016",
@@ -3544,7 +3542,7 @@
"description": [
"If you have multiple conditions that need to be addressed, you can chain if
statements together with else if
statements.",
"if (num > 15) {", - "
return \"Bigger than 15\";
} else if (num < 5) {
return \"Smaller than 5\";
} else {
return \"Between 5 and 15\";
}
else if
statements."
],
"releasedOn": "January 1, 2016",
@@ -3604,7 +3602,7 @@
"function bar(x) {", "While these two functions look nearly identical if we pass a number to both we get different outputs.", "
if (x < 2) {
return \"Less than two\";
} else if (x < 1) {
return \"Less than one\";
} else {
return \"Greater than or equal to two\";
}
}
foo(0) // \"Less than one\"", - "
bar(0) // \"Less than two\"
if/else
statements can be chained together for complex logic. Here is pseudocode of multiple chained if
/ else if
statements:",
"if (condition1) {", - "
statement1
} else if (condition2) {
statement2
} else if (condition3) {
statement3
. . .
} else {
statementN
}
if
/else if
statements to fulfill the following conditions:",
"num < 5
- return \"Tiny\"num < 10
- return \"Small\"num < 15
- return \"Medium\"num < 20
- return \"Large\"num >= 20
- return \"Huge\""
],
@@ -3766,7 +3764,7 @@
"Here is a pseudocode example:",
"switch (num) {", "
case value1:
statement1;
break;
case value2:
statement2;
break;
...
case valueN:
statementN;
break;
}
case
values are tested with strict equality (===
). The break
tells JavaScript to stop executing statements. If the break
is omitted, the next statement will be executed.",
- "val
and sets answer
for the following conditions:1
- \"alpha\"2
- \"beta\"3
- \"gamma\"4
- \"delta\""
],
"releasedOn": "January 1, 2016",
@@ -3822,7 +3820,7 @@
"In a switch
statement you may not be able to specify all possible values as case
statements. Instead, you can add the default
statement which will be executed if no matching case
statements are found. Think of it like the final else
statement in an if/else
chain.",
"A default
statement should be the last case.",
"switch (num) {", - "
case value1:
statement1;
break;
case value2:
statement2;
break;
...
default:
defaultStatement;
}
answer
for the following conditions:\"a\"
- \"apple\"\"b\"
- \"bird\"\"c\"
- \"cat\"default
- \"stuff\""
],
"releasedOn": "January 1, 2016",
@@ -3876,7 +3874,7 @@
"If the break
statement is omitted from a switch
statement's case
, the following case
statement(s) are executed until a break
is encountered. If you have multiple inputs with the same output, you can represent them in a switch
statement like this:",
"switch(val) {", "Cases for 1, 2, and 3 will all produce the same result.", - "
case 1:
case 2:
case 3:
result = \"1, 2, or 3\";
break;
case 4:
result = \"4 alone\";
}
answer
for the following ranges:1-3
- \"Low\"4-6
- \"Mid\"7-9
- \"High\"",
"Notecase
statement for each number in the range."
],
@@ -3936,7 +3934,7 @@
"if (val === 1) {", "can be replaced with:", "
answer = \"a\";
} else if (val === 2) {
answer = \"b\";
} else {
answer = \"c\";
}
switch (val) {", - "
case 1:
answer = \"a\";
break;
case 2:
answer = \"b\";
break;
default:
answer = \"c\";
}
if
/else if
statements into a switch
statement."
],
"releasedOn": "January 1, 2016",
@@ -4005,7 +4003,7 @@
"function isEqual(a,b) {", "But there's a better way to do this. Since
if (a === b) {
return true;
} else {
return false;
}
}
===
returns true
or false
, we can return the result of the comparison:",
"function isEqual(a,b) {", - "
return a === b;
}
isLess
to remove the if/else
statements."
],
"releasedOn": "January 1, 2016",
@@ -4058,7 +4056,7 @@
"Example",
"function myFun() {", "The above outputs \"Hello\" to the console, returns \"World\", but
console.log(\"Hello\");
return \"World\";
console.log(\"byebye\")
}
myFun();
\"byebye\"
is never output, because the function exits at the return
statement.",
- "abTest
so that if a
or b
are less than 0
the function will immediately exit with a value of undefined
.",
"Hintundefined
is a keyword, not a string."
],
@@ -4172,7 +4170,7 @@
"Here's a sample object:",
"var cat = {", "Objects are useful for storing data in a structured way, and can represent real world objects, like a cat.", - "
\"name\": \"Whiskers\",
\"legs\": 4,
\"tails\": 1,
\"enemies\": [\"Water\", \"Dogs\"]
};
myDog
which contains the properties \"name\"
(a string), \"legs\"
, \"tails\"
and \"friends\"
.",
"You can set these object properties to whatever values you want, as long \"name\"
is a string, \"legs\"
and \"tails\"
are numbers, and \"friends\"
is an array."
],
@@ -4237,7 +4235,7 @@
"The dot operator is what you use when you know the name of the property you're trying to access ahead of time.",
"Here is a sample of using the dot operator (.
) to read an object property:",
"var myObj = {", - "
prop1: \"val1\",
prop2: \"val2\"
};
var prop1val = myObj.prop1; // val1
var prop2val = myObj.prop2; // val2
testObj
using dot notation. Set the variable hatValue
equal to the object property hat
and set the variable shirtValue
equal to the object property shirt
."
],
"releasedOn": "January 1, 2016",
@@ -4291,7 +4289,7 @@
"Here is a sample of using bracket notation to read an object property:",
"var myObj = {", "Note that property names with spaces in them must be in quotes (single or double).", - "
\"Space Name\": \"Kirk\",
\"More Space\": \"Spock\"
};
myObj[\"Space Name\"]; // Kirk
myObj['More Space']; // Spock
\"an entree\"
and \"the drink\"
of testObj
using bracket notation and assign them to entreeValue
and drinkValue
respectively."
],
"releasedOn": "January 1, 2016",
@@ -4347,7 +4345,7 @@
"Here is one more:",
"var myDog = \"Hunter\";", "Note that we do not use quotes around the variable name when using it to access the property because we are using the value of the variable, not the name", - "
var dogs = {
Fido: \"Mutt\",\n Hunter: \"Doberman\",\n Snoopie: \"Beagle\"
}
var breed = dogs[myDog];
console.log(breed);// \"Doberman\"
playerNumber
variable to lookup player 16
in testObj
using bracket notation. Then assign that name to the player
variable."
],
"releasedOn": "January 1, 2016",
@@ -4406,7 +4404,7 @@
"ourDog.name = \"Happy Camper\";
or",
"ourDog[\"name\"] = \"Happy Camper\";
",
"Now when we evaluate ourDog.name
, instead of getting \"Camper\", we'll get his new name, \"Happy Camper\".",
- "myDog
object's name property. Let's change her name from \"Coder\" to \"Happy Coder\". You can use either dot or bracket notation."
],
"challengeSeed": [
@@ -4475,7 +4473,7 @@
"or",
"ourDog[\"bark\"] = \"bow-wow\";
",
"Now when we evaluate ourDog.bark
, we'll get his bark, \"bow-wow\".",
- "\"bark\"
property to myDog
and set it to a dog sound, such as \"woof\". You may use either dot or bracket notation."
],
"challengeSeed": [
@@ -4532,7 +4530,7 @@
"description": [
"We can also delete properties from objects like this:",
"delete ourDog.bark;
",
- "\"tails\"
property from myDog
. You may use either dot or bracket notation."
],
"challengeSeed": [
@@ -4591,7 +4589,7 @@
"Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to \"lookup\" values rather than a switch
statement or an if/else
chain. This is most useful when you know that your input data is limited to a certain range.",
"Here is an example of a simple reverse alphabet lookup:",
"var alpha = {", - "
1:\"Z\",
2:\"Y\",
3:\"X\",
4:\"W\",
...
24:\"C\",
25:\"B\",
26:\"A\"
};
alpha[2]; // \"Y\"
alpha[24]; // \"C\"
var value = 2;
alpha[value]; // \"Y\"
lookup
. Use it to lookup val
and assign the associated string to the result
variable."
],
"releasedOn": "January 1, 2016",
@@ -4664,7 +4662,7 @@
"Sometimes it is useful to check if the property of a given object exists or not. We can use the .hasOwnProperty(propname)
method of objects to determine if that object has the given property name. .hasOwnProperty()
returns true
or false
if the property is found or not.",
"Example",
"var myObj = {", - "
top: \"hat\",
bottom: \"pants\"
};
myObj.hasOwnProperty(\"top\"); // true
myObj.hasOwnProperty(\"middle\"); // false
checkObj
to test myObj
for checkProp
. If the property is found, return that property's value. If not, return \"Not Found\"
."
],
"releasedOn": "January 1, 2016",
@@ -4723,7 +4721,7 @@
"JavaScript Object Notation or JSON
is a related data interchange format used to store data.",
"{", "Note
\"artist\": \"Daft Punk\",
\"title\": \"Homework\",
\"release_year\": 1997,
\"formats\": [
\"CD\",
\"Cassette\",
\"LP\"
],
\"gold\": true
}
myMusic
array. Add artist
and title
strings, release_year
number, and a formats
array of strings."
],
"releasedOn": "January 1, 2016",
@@ -4784,7 +4782,7 @@
"The sub-properties of objects can be accessed by chaining together the dot or bracket notation.",
"Here is a nested object:",
"var ourStorage = {", - "
\"desk\": {
\"drawer\": \"stapler\"
},
\"cabinet\": {
\"top drawer\": {
\"folder1\": \"a file\",
\"folder2\": \"secrets\"
},
\"bottom drawer\": \"soda\"
}
};
ourStorage.cabinet[\"top drawer\"].folder2; // \"secrets\"
ourStorage.desk.drawer; // \"stapler\"
myStorage
object and assign the contents of the glove box
property to the gloveBoxContents
variable. Use bracket notation for properties with a space in their name."
],
"releasedOn": "January 1, 2016",
@@ -4844,7 +4842,7 @@
"As we have seen in earlier examples, objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.",
"Here is an example of how to access a nested array:",
"var ourPets = [", - "
{
animalType: \"cat\",
names: [
\"Meowzer\",
\"Fluffy\",
\"Kit-Cat\"
]
},
{
animalType: \"dog\",
names: [
\"Spot\",
\"Bowser\",
\"Frankie\"
]
}
];
ourPets[0].names[1]; // \"Fluffy\"
ourPets[1].names[0]; // \"Spot\"
myPlants
using object dot and array bracket notation."
],
"releasedOn": "January 1, 2016",
@@ -5003,7 +5001,7 @@
"Another type of JavaScript loop is called a \"while loop
\", because it runs \"while\" a specified condition is true and stops once that condition is no longer true.",
"var ourArray = [];", "Let's try getting a while loop to work by pushing values to an array.", - "
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
myArray
using a while
loop."
],
"challengeSeed": [
@@ -5059,7 +5057,7 @@
"In the following example we initialize with i = 0
and iterate while our condition i < 5
is true. We'll increment i
by 1
in each loop iteration with i++
as our final-expression
.",
"var ourArray = [];", "
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
ourArray
will now contain [0,1,2,3,4]
.",
- "for
loop to work to push the values 1 through 5 onto myArray
."
],
"challengeSeed": [
@@ -5121,7 +5119,7 @@
"var ourArray = [];", "
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
ourArray
will now contain [0,2,4,6,8]
.",
"Let's change our initialization
so we can count by odd numbers.",
- "myArray
using a for
loop."
],
"challengeSeed": [
@@ -5179,7 +5177,7 @@
"var ourArray = [];", "
for (var i=10; i > 0; i-=2) {
ourArray.push(i);
}
ourArray
will now contain [10,8,6,4,2]
.",
"Let's change our initialization
and final-expression
so we can count backward by twos by odd numbers.",
- "myArray
using a for
loop."
],
"challengeSeed": [
@@ -5236,7 +5234,7 @@
"A common task in JavaScript is to iterate through the contents of an array. One way to do that is with a for
loop. This code will output each element of the array arr
to the console:",
"var arr = [10,9,8,7,6];", "Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1. Our condition for this loop is
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
i < arr.length
, which stops when i
is at length - 1.",
- "total
to 0
. Use a for
loop to add the value of each element of the myArr
array to total
."
],
"releasedOn": "January 1, 2016",
@@ -5290,7 +5288,7 @@
"If you have a multi-dimensional array, you can use the same logic as the prior waypoint to loop through both the array and any sub-arrays. Here is an example:",
"var arr = [", "This outputs each sub-element in
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
arr
one at a time. Note that for the inner loop, we are checking the .length
of arr[i]
, since arr[i]
is itself an array.",
- "multiplyAll
so that it multiplies the product
variable by each number in the sub-arrays of arr
"
],
"releasedOn": "January 1, 2016",
@@ -5419,7 +5417,7 @@
"Random numbers are useful for creating random behavior.",
"JavaScript has a Math.random()
function that generates a random decimal number between 0
(inclusive) and not quite up to 1
(exclusive). Thus Math.random()
can return a 0
but never quite return a 1
",
"Notereturn
executes, so we can return
the value of the Math.random()
function.",
- "randomFraction
to return a random number instead of returning 0
."
],
"challengeSeed": [
@@ -5468,7 +5466,7 @@
"Putting everything together, this is what our code looks like:",
"Math.floor(Math.random() * 20);
",
"We are calling Math.random()
, multiplying the result by 20, then passing the value to Math.floor()
function to round the value down to the nearest whole number.",
- "0
and 9
."
],
"challengeSeed": [
@@ -5522,7 +5520,7 @@
"To do this, we'll define a minimum number min
and a maximum number max
.",
"Here's the formula we'll use. Take a moment to read it and try to understand what this code is doing:",
"Math.floor(Math.random() * (max - min + 1)) + min
",
- "randomRange
that takes a range myMin
and myMax
and returns a random number that's greater than or equal to myMin
, and is less than or equal to myMax
, inclusive."
],
"challengeSeed": [
diff --git a/challenges/02-javascript-algorithms-and-data-structures/debugging.json b/challenges/02-javascript-algorithms-and-data-structures/debugging.json
index 46c4e321f4..c36b67b290 100644
--- a/challenges/02-javascript-algorithms-and-data-structures/debugging.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/debugging.json
@@ -55,7 +55,7 @@
"The console.log()
method, which \"prints\" the output of what's within its parentheses to the console, will likely be the most helpful debugging tool. Placing it at strategic points in your code can show you the intermediate values of variables. It's good practice to have an idea of what the output should be before looking at what it is. Having check points to see the status of your calculations throughout your code will help narrow down where the problem is.",
"Here's an example to print 'Hello world!' to the console:",
"console.log('Hello world!');
",
- "console.log()
method to print the value of the variable a
where noted in the code."
],
"challengeSeed": [
@@ -104,7 +104,7 @@
"Here are some examples using typeof
:",
"console.log(typeof \"\"); // outputs \"string\"", "JavaScript recognizes six primitive (immutable) data types:
console.log(typeof 0); // outputs \"number\"
console.log(typeof []); // outputs \"object\"
console.log(typeof {}); // outputs \"object\"
Boolean
, Null
, Undefined
, Number
, String
, and Symbol
(new with ES6) and one type for mutable items: Object
. Note that in JavaScript, arrays are technically a type of object.",
- "console.log()
statements to check the typeof
each of the two variables seven
and three
in the code."
],
"challengeSeed": [
@@ -149,7 +149,7 @@
"description": [
"The console.log()
and typeof
methods are the two primary ways to check intermediate values and types of program output. Now it's time to get into the common forms that bugs take. One syntax-level issue that fast typers can commiserate with is the humble spelling error.",
"Transposed, missing, or mis-capitalized characters in a variable or function name will have the browser looking for an object that doesn't exist - and complain in the form of a reference error. JavaScript variable and function names are case-sensitive.",
- "netWorkingCapital
calculation works."
],
"challengeSeed": [
@@ -196,7 +196,7 @@
"description": [
"Another syntax error to be aware of is that all opening parentheses, brackets, curly braces, and quotes have a closing pair. Forgetting a piece tends to happen when you're editing existing code and inserting items with one of the pair types. Also, take care when nesting code blocks into others, such as adding a callback function as an argument to a method.",
"One way to avoid this mistake is as soon as the opening character is typed, immediately include the closing match, then move the cursor back between them and continue coding. Fortunately, most modern code editors generate the second half of the pair automatically.",
- "// These are correct:", "Of course, it is okay to use only one style of quotes. You can escape the quotes inside the string by using the backslash (\\) escape character:", "
const grouchoContraction = \"I've had a perfectly wonderful evening, but this wasn't it.\";
const quoteInString = \"Groucho Marx once said 'Quote me as saying I was mis-quoted.'\";
// This is incorrect:
const uhOhGroucho = 'I've had a perfectly wonderful evening, but this wasn't it.';
// Correct use of same quotes:", - "
const allSameQuotes = 'I\\'ve had a perfectly wonderful evening, but this wasn\\'t it.';
href
value, or escape the existing ones. Keep the double quote marks around the entire string."
],
"challengeSeed": [
@@ -286,7 +286,7 @@
"As covered in previous challenges, the assignment operator (=
) in JavaScript assigns a value to a variable name. And the ==
and ===
operators check for equality (the triple ===
tests for strict equality, meaning both value and type are the same).",
"The code below assigns x
to be 2, which evaluates as true
. Almost every value on its own in JavaScript evaluates to true
, except what are known as the \"falsy\" values: false
, 0
, \"\"
(an empty string), NaN
, undefined
, and null
.",
"let x = 1;", - "
let y = 2;
if (x = y) {
// this code block will run for any value of y (unless y were originally set as a falsy)
} else {
// this code block is what should run (but won't) in this example
}
result
."
],
"challengeSeed": [
@@ -337,7 +337,7 @@
"When a function or method doesn't take any arguments, you may forget to include the (empty) opening and closing parentheses when calling it. Often times the result of a function call is saved in a variable for other use in your code. This error can be detected by logging variable values (or their types) to the console and seeing that one is set to a function reference, instead of the expected value the function returns.",
"The variables in the following example are different:",
"function myFunction() {", - "
return \"You rock!\";
}
let varOne = myFunction; // set to equal a function
let varTwo = myFunction(); // set to equal the string \"You rock!\"
result
is set to the value returned from calling the function getNine
."
],
"challengeSeed": [
@@ -383,7 +383,7 @@
"title": "Catch Arguments Passed in the Wrong Order When Calling a Function",
"description": [
"Continuing the discussion on calling functions, the next bug to watch out for is when a function's arguments are supplied in the incorrect order. If the arguments are different types, such as a function expecting an array and an integer, this will likely throw a runtime error. If the arguments are the same type (all integers, for example), then the logic of the code won't make sense. Make sure to supply all required arguments, in the proper order to avoid these issues.",
- "positivePowers
raises a base to a positive exponent. Unfortunately, it's not called properly - fix the code so the value of power
is the expected 8."
],
"challengeSeed": [
@@ -436,7 +436,7 @@
"Off by one errors
(sometimes called OBOE) crop up when you're trying to target a specific index of a string or array (to slice or access a segment), or when looping over the indices of them. JavaScript indexing starts at zero, not one, which means the last index is always one less than the length of the item. If you try to access an index equal to the length, the program may throw an \"index out of range\" reference error or print undefined
.",
"When you use string or array methods that take index ranges as arguments, it helps to read the documentation and understand if they are inclusive (the item at the given index is part of what's returned) or not. Here are some examples of off by one errors:",
"let alphabet = \"abcdefghijklmnopqrstuvwxyz\";", - "
let len = alphabet.length;
for (let i = 0; i <= len; i++) {
// loops one too many times at the end
console.log(alphabet[i]);
}
for (let j = 1; j < len; j++) {
// loops one too few times and misses the first character at index 0
console.log(alphabet[j]);
}
for (let k = 0; k < len; k++) {
// Goldilocks approves - this is just right
console.log(alphabet[k]);
}
console.log()
can uncover buggy behavior related to resetting, or failing to reset a variable.",
- "m
rows and n
columns of zeroes. Unfortunately, it's not producing the expected output because the row
variable isn't being reinitialized (set back to an empty array) in the outer loop. Fix the code so it returns a correct 3x2 array of zeroes, which looks like [[0, 0], [0, 0], [0, 0]]
."
],
"challengeSeed": [
@@ -547,7 +547,7 @@
"There was an example of an infinite loop in the introduction to this section - it had no terminal condition to break out of the while
loop inside loopy()
. Do NOT call this function!",
"function loopy() {", "It's the programmer's job to ensure that the terminal condition, which tells the program when to break out of the loop code, is eventually reached. One error is incrementing or decrementing a counter variable in the wrong direction from the terminal condition. Another one is accidentally resetting a counter or index variable within the loop code, instead of incrementing or decrementing it.", - "
while(true) {
console.log(\"Hello, world!\");
}
}
myFunc()
function contains an infinite loop because the terminal condition i != 4
will never evaluate to false
(and break the looping) - i
will increment by 2 each pass, and jump right over 4 since i
is odd to start. Fix the comparison operator in the terminal condition so the loop only runs for i
less than or equal to 4."
],
"challengeSeed": [
diff --git a/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json b/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json
index 1532d4c25b..3f4c6317ec 100644
--- a/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/functional-programming.json
@@ -43,7 +43,7 @@
"1) Isolated functions - there is no dependence on the state of the program, which includes global variables that are subject to change",
"2) Pure functions - the same input always gives the same output",
"3) Functions with limited side effects - any changes, or mutations, to the state of the program outside the function are carefully controlled",
- "prepareTea
and getTea
functions are already defined for you. Call the getTea
function to get 40 cups of tea for the team, and store them in the tea4TeamFCC
variable."
],
@@ -116,7 +116,7 @@
"Functions that can be assigned to a variable, passed into another function, or returned from another function just like any other normal value, are called first class
functions. In JavaScript, all functions are first class
functions.",
"The functions that take a function as an argument, or return a function as a return value are called higher order
functions.",
"When the functions are passed in to another function or returned from another function, then those functions which gets passed in or returned can be called a lambda
.",
- "tea4GreenTeamFCC
and tea4BlackTeamFCC
variables, respectively. Note that the getTea
function has been modified so it now takes a function as the first argument.",
"Note: The data (the number of cups of tea) is supplied as the last argument. We'll discuss this more in later lessons."
],
@@ -283,7 +283,7 @@
"The previous example didn't have any complicated operations but the splice
method changed the original array, and resulted in a bug.",
"Recall that in functional programming, changing or altering things is called mutation
, and the outcome is called a side effect
. A function, ideally, should be a pure function
, meaning that it does not cause any side effects.",
"Let's try to master this discipline and not alter any variable or object in our code.",
- "incrementer
so it returns the value of the global variable fixedValue
increased by one."
],
"challengeSeed": [
@@ -337,7 +337,7 @@
"There are several good consequences from this principle. The function is easier to test, you know exactly what input it takes, and it won't depend on anything else in your program.",
"This can give you more confidence when you alter, remove, or add new code. You would know what you can or cannot change and you can see where the potential traps are.",
"Finally, the function would always produce the same output for the same set of inputs, no matter what part of the code executes it.",
- "incrementer
function to clearly declare its dependencies.",
"Write the incrementer
function so it takes an argument, and then increases the value by one."
],
@@ -391,7 +391,7 @@
"1) Don't alter a variable or object - create new variables and objects and return them if need be from a function.",
"2) Declare function arguments - any computation inside a function depends only on the arguments, and not on any global object or variable.",
"Adding one to a number is not very exciting, but we can apply these principles when working with arrays or more complex objects.",
- "bookList
is not changed inside either function. The add
function should add the given bookName
to the end of an array. The remove
function should remove the given bookName
from an array. Both functions should return an array, and any new parameters should be added before the bookName
one."
],
"challengeSeed": [
@@ -470,7 +470,7 @@
"It would make sense to be able to pass them as arguments to other functions, and return a function from another function. Functions are considered First Class Objects
in JavaScript, which means they can be used like any other object. They can be saved in variables, stored in an object, or passed as function arguments.",
"Let's start with some simple array functions, which are methods on the array object prototype. In this exercise we are looking at Array.prototype.map()
, or more simply map
.",
"Remember that the map
method is a way to iterate over each item in an array. It creates a new array (without changing the original one) after applying a callback function to every element.",
- "watchList
array holds objects with information on several movies. Use map
to pull the title and rating from watchList
and save the new array in the rating
variable. The code in the editor currently uses a for
loop to do this, replace the loop functionality with your map
expression."
],
"challengeSeed": [
@@ -636,7 +636,7 @@
"In other words, map
is a pure function, and its output depends solely on its inputs. Plus, it takes another function as its argument.",
"It would teach us a lot about map
to try to implement a version of it that behaves exactly like the Array.prototype.map()
with a for
loop or Array.prototype.forEach()
.",
"Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.",
- "Array.prototype.myMap()
, which should behave exactly like Array.prototype.map()
. You may use a for
loop or the forEach
method."
],
"challengeSeed": [
@@ -689,7 +689,7 @@
"description": [
"Another useful array function is Array.prototype.filter()
, or simply filter()
. The filter
method returns a new array which is at most as long as the original array, but usually has fewer items.",
"Filter
doesn't alter the original array, just like map
. It takes a callback function that applies the logic inside the callback on each element of the array. If an element returns true based on the criteria in the callback function, then it is included in the new array.",
- "watchList
holds an array of objects with information on several movies. Use a combination of filter
and map
to return a new array of objects with only title
and rating
keys, but where imdbRating
is greater than or equal to 8.0. Note that the rating values are saved as strings in the object and you may want to convert them into numbers to perform mathematical operations on them."
],
"challengeSeed": [
@@ -850,7 +850,7 @@
"description": [
"It would teach us a lot about the filter
method if we try to implement a version of it that behaves exactly like Array.prototype.filter()
. It can use either a for
loop or Array.prototype.forEach()
.",
"Note: A pure function is allowed to alter local variables defined within its scope, although, it's preferable to avoid that as well.",
- "Array.prototype.myFilter()
, which should behave exactly like Array.prototype.filter()
. You may use a for
loop or the Array.prototype.forEach()
method."
],
"challengeSeed": [
@@ -904,7 +904,7 @@
"The slice
method returns a copy of certain elements of an array. It can take two arguments, the first gives the index of where to begin the slice, the second is the index for where to end the slice (and it's non-inclusive). If the arguments are not provided, the default is to start at the beginning of the array through the end, which is an easy way to make a copy of the entire array. The slice
method does not mutate the original array, but returns a new one.",
"Here's an example:",
"var arr = [\"Cat\", \"Dog\", \"Tiger\", \"Zebra\"];", - "
var newArray = arr.slice(1, 3);
// Sets newArray to [\"Dog\", \"Tiger\"]
slice
method in the sliceArray
function to return part of the anim
array given the provided beginSlice
and endSlice
indices. The function should return an array."
],
"challengeSeed": [
@@ -954,7 +954,7 @@
"A common pattern while working with arrays is when you want to remove items and keep the rest of the array. JavaScript offers the splice
method for this, which takes arguments for the index of where to start removing items, then the number of items to remove. If the second argument is not provided, the default is to remove items through the end. However, the splice
method mutates the original array it is called on. Here's an example:",
"var cities = [\"Chicago\", \"Delhi\", \"Islamabad\", \"London\", \"Berlin\"];", "As we saw in the last challenge, the
cities.splice(3, 1); // Returns \"London\" and deletes it from the cities array
// cities is now [\"Chicago\", \"Delhi\", \"Islamabad\", \"Berlin\"]
slice
method does not mutate the original array, but returns a new one which can be saved into a variable. Recall that the slice
method takes two arguments for the indices to begin and end the slice (the end is non-inclusive), and returns those items in a new array. Using the slice
method instead of splice
helps to avoid any array-mutating side effects.",
- "nonMutatingSplice
by using slice
instead of splice
. It should limit the provided cities
array to a length of 3, and return a new array with only the first three items.",
"Do not mutate the original array provided to the function."
],
@@ -1003,7 +1003,7 @@
"description": [
"Concatenation
means to join items end to end. JavaScript offers the concat
method for both strings and arrays that work in the same way. For arrays, the method is called on one, then another array is provided as the argument to concat
, which is added to the end of the first array. It returns a new array and does not mutate either of the original arrays. Here's an example:",
"[1, 2, 3].concat([4, 5, 6]);", - "
// Returns a new array [1, 2, 3, 4, 5, 6]
concat
method in the nonMutatingConcat
function to concatenate attach
to the end of original
. The function should return the concatenated array."
],
"challengeSeed": [
@@ -1054,7 +1054,7 @@
"The last challenge introduced the concat
method as a way to combine arrays into a new one without mutating the original arrays. Compare concat
to the push
method. Push
adds an item to the end of the same array it is called on, which mutates that array. Here's an example:",
"var arr = [1, 2, 3];", "
arr.push([4, 5, 6]);
// arr is changed to [1, 2, 3, 4, 5, 6]
// Not the functional programming way
Concat
offers a way to add new items to the end of an array without any mutating side effects.",
- "nonMutatingPush
function so it uses concat
to add newItem
to the end of original
instead of push
. The function should return an array."
],
"challengeSeed": [
@@ -1106,7 +1106,7 @@
"This is not the case with the filter
and map
methods since they do not allow interaction between two different elements of the array. For example, if you want to compare elements of the array, or add them together, filter
or map
could not process that.",
"The reduce
method allows for more general forms of array processing, and it's possible to show that both filter
and map
can be derived as a special application of reduce
.",
"However, before we get there, let's practice using reduce
first.",
- "watchList
holds an array of objects with information on several movies. Use reduce
to find the average IMDB rating of the movies directed by Christopher Nolan. Recall from prior challenges how to filter
data and map
over it to pull what you need. You may need to create other variables, but save the final average into the variable averageRating
. Note that the rating values are saved as strings in the object and need to be converted into numbers before they are used in any mathematical operations."
],
"challengeSeed": [
@@ -1273,7 +1273,7 @@
"For example:",
"function ascendingOrder(arr) {", "Note: It's encouraged to provide a callback function to specify how to sort the array items. JavaScript's default sorting method is by string Unicode point value, which may return unexpected results.", - "
return arr.sort(function(a, b) {
return a - b;
});
}
ascendingOrder([1, 5, 2, 3, 4]);
// Returns [1, 2, 3, 4, 5]
function reverseAlpha(arr) {
return arr.sort(function(a, b) {
return a < b;
});
}
reverseAlpha(['l', 'h', 'z', 'b', 's']);
// Returns ['z', 's', 'l', 'h', 'b']
sort
method in the alphabeticalOrder
function to sort the elements of arr
in alphabetical order."
],
"challengeSeed": [
@@ -1319,7 +1319,7 @@
"title": "Return a Sorted Array Without Changing the Original Array",
"description": [
"A side effect of the sort
method is that it changes the order of the elements in the original array. In other words, it mutates the array in place. One way to avoid this is to first concatenate an empty array to the one being sorted (remember that concat
returns a new array), then run the sort
method.",
- "sort
method in the nonMutatingSort
function to sort the elements of an array in ascending order. The function should return a new array, and not mutate the globalArray
variable."
],
"challengeSeed": [
@@ -1369,7 +1369,7 @@
"Here are two examples that split one string by spaces, then another by digits using a regular expression:",
"var str = \"Hello World\";", "Since strings are immutable, the
var bySpace = str.split(\" \");
// Sets bySpace to [\"Hello\", \"World\"]
var otherString = \"How9are7you2today\";
var byDigits = str.split(/\\d/);
// Sets byDigits to [\"How\", \"are\", \"you\", \"today\"]
split
method makes it easier to work with them.",
- "split
method inside the splitify
function to split str
into an array of words. The function should return the array. Note that the words are not always separated by spaces, and the array should not contain punctuation."
],
"challengeSeed": [
@@ -1419,7 +1419,7 @@
"The join
method is used to join the elements of an array together to create a string. It takes an argument for the delimiter that is used to separate the array elements in the string.",
"Here's an example:",
"var arr = [\"Hello\", \"World\"];", - "
var str = arr.join(\" \");
// Sets str to \"Hello World\"
join
method (among others) inside the sentensify
function to make a sentence from the words in the string str
. The function should return a string. For example, \"I-like-Star-Wars\" would be converted to \"I like Star Wars\". For this challenge, do not use the replace
method."
],
"challengeSeed": [
@@ -1471,7 +1471,7 @@
"The last several challenges covered a number of useful array and string methods that follow functional programming principles. We've also learned about reduce
, which is a powerful method used to reduce problems to simpler forms. From computing averages to sorting, any array operation can be achieved by applying it. Recall that map
and filter
are special cases of reduce
.",
"Let's combine what we've learned to solve a practical problem.",
"Many content management sites (CMS) have the titles of a post added to part of the URL for simple bookmarking purposes. For example, if you write a Medium post titled \"Stop Using Reduce\", it's likely the URL would have some form of the title string in it (\".../stop-using-reduce\"). You may have already noticed this on the Free Code Camp site.",
- "urlSlug
function so it converts a string title
and returns the hyphenated version for the URL. You can use any of the methods covered in this section, and don't use replace
. Here are the requirements:",
"The input is a string with spaces and title-cased words",
"The output is a string with the spaces between words replaced by a hyphen (-
)",
@@ -1532,7 +1532,7 @@
"The every
method works with arrays to check if every element passes a particular test. It returns a Boolean value - true
if all values meet the criteria, false
if not.",
"For example, the following code would check if every element in the numbers
array is less than 10:",
"var numbers = [1, 5, 8, 0, 10, 11];", - "
numbers.every(function(currentValue) {
return currentValue < 10;
});
// Returns false
every
method inside the checkPositive
function to check if every element in arr
is positive. The function should return a Boolean value."
],
"challengeSeed": [
@@ -1580,7 +1580,7 @@
"The some
method works with arrays to check if any element passes a particular test. It returns a Boolean value - true
if any of the values meet the criteria, false
if not.",
"For example, the following code would check if any element in the numbers
array is less than 10:",
"var numbers = [10, 50, 8, 220, 110, 11];", - "
numbers.some(function(currentValue) {
return currentValue < 10;
});
// Returns true
some
method inside the checkPositive
function to check if any element in arr
is positive. The function should return a Boolean value."
],
"challengeSeed": [
@@ -1634,7 +1634,7 @@
"Similarly, partial application
can be described as applying a few arguments to a function at a time and returning another function that is applied to more arguments.",
"Here's an example:",
"//Impartial function", - "
function impartial(x, y, z) {
return x + y + z;
}
var partialFn = impartial.bind(this, 1, 2);
partialFn(10); // Returns 13
add
function so it uses currying to add parameters x
, y
, and z
."
],
"challengeSeed": [
diff --git a/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json b/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json
index 5ef6159d29..a1ff7a9cf5 100644
--- a/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/object-oriented-programming.json
@@ -44,7 +44,7 @@
"Objects
in JavaScript are used to model real-world objects, giving them properties
and behavior just like their real-world counterparts. Here's an example using these concepts to create a duck
object
:",
"let duck = {", "This
name: \"Aflac\",
numLegs: 2
};
duck
object
has two property/value pairs: a name
of \"Aflac\" and a numLegs
of 2.",
- "dog
object
with name
and numLegs
properties, and set them to a string and a number, respectively."
],
"challengeSeed": [
@@ -87,7 +87,7 @@
"The last challenge created an object
with various properties
, now you'll see how to access the values of those properties
. Here's an example:",
"let duck = {", "Dot notation is used on the
name: \"Aflac\",
numLegs: 2
};
console.log(duck.name);
// This prints \"Aflac\" to the console
object
name, duck
, followed by the name of the property
, name
, to access the value of \"Aflac\".",
- "properties
of the dog
object below to your console."
],
"challengeSeed": [
@@ -135,7 +135,7 @@
"let duck = {", "The example adds the
name: \"Aflac\",
numLegs: 2,
sayName: function() {return \"The name of this duck is \" + duck.name + \".\";}
};
duck.sayName();
// Returns \"The name of this duck is Aflac.\"
sayName
method
, which is a function that returns a sentence giving the name of the duck
.",
"Notice that the method
accessed the name
property in the return statement using duck.name
. The next challenge will cover another way to do this.",
- "dog
object
, give it a method called sayLegs
. The method should return the sentence \"This dog has 4 legs.\""
],
"challengeSeed": [
@@ -185,7 +185,7 @@
"let duck = {", "
name: \"Aflac\",
numLegs: 2,
sayName: function() {return \"The name of this duck is \" + this.name + \".\";}
};
This
is a deep topic, and the above example is only one way to use it. In the current context, this
refers to the object that the method is associated with: duck
.",
"If the object's name is changed to mallard
, it is not necessary to find all the references to duck
in the code. It makes the code reusable and easier to read.",
- "dog.sayLegs
method to remove any references to dog
. Use the duck
example for guidance."
],
"challengeSeed": [
@@ -239,7 +239,7 @@
"Constructors
use the keyword this
to set properties of the object they will create. Inside the constructor
, this
refers to the new object it will create.Constructors
define properties and behaviors instead of returning a value as other functions might.constructor
, Dog
, with properties name
, color
, and numLegs
that are set to a string, a string, and a number, respectively."
],
"challengeSeed": [
@@ -286,7 +286,7 @@
"blueBird.name; // => Albert", "Just like any other object, its properties can be accessed and modified:", "
blueBird.color; // => blue
blueBird.numLegs; // => 2
blueBird.name = 'Elvira';", - "
blueBird.name; // => Elvira
Dog
constructor from the last lesson to create a new instance of Dog
, assigning it to a variable hound
."
],
"challengeSeed": [
@@ -341,7 +341,7 @@
"The cardinal
has these properties:",
"cardinal.name // => Bruce", "The constructor is more flexible. It's now possible to define the properties for each
cardinal.color // => red
cardinal.numLegs // => 2
Bird
at the time it is created, which is one way that JavaScript constructors are so useful. They group objects together based on shared characteristics and behavior and define a blueprint that automates their creation.",
- "Dog
constructor. This time, set it up to take the parameters name
and color
, and have the property numLegs
fixed at 4. Then create a new Dog
saved in a variable terrier
. Pass it two strings as arguments for the name
and color
properties."
],
"challengeSeed": [
@@ -388,7 +388,7 @@
"let Bird = function(name, color) {", "If an object is created without using a constructor,
this.name = name;
this.color = color;
this.numLegs = 2;
}
let crow = new Bird(\"Alexis\", \"black\");
crow instanceof Bird; // => true
instanceof
will verify that it is not an instance of that constructor:",
"let canary = {", - "
name: \"Mildred\",
color: \"Yellow\",
numLegs: 2
};
canary instanceof Bird; // => false
House
constructor, calling it myHouse
and passing a number of bedrooms. Then, use instanceof
to verify that it is an instance of House
."
],
"challengeSeed": [
@@ -437,7 +437,7 @@
"In fact every instance of Bird
will have its own copy of these properties.",
"The following code adds all of the own
properties of duck
to the array ownProps
:",
"let ownProps = [];", - "
for (let property in duck) {
if(duck.hasOwnProperty(property)) {
ownProps.push(property);
}
}
console.log(ownProps); // prints [ \"name\", \"numLegs\" ]
own
properties of canary
to the array ownProps
."
],
"challengeSeed": [
@@ -491,7 +491,7 @@
"console.log(duck.numLegs); // prints 2", "Since all instances automatically have the properties on the
console.log(canary.numLegs); // prints 2
prototype
, think of a prototype
as a \"recipe\" for creating objects.",
"Note that the prototype
for duck
and canary
is part of the Bird
constructor as Bird.prototype
. Nearly every object in JavaScript has a prototype
property which is part of the constructor function that created it.",
- "numLegs
property to the prototype
of Dog
"
],
"challengeSeed": [
@@ -541,7 +541,7 @@
"function Bird(name) {", "Here is how you add
this.name = name; //own property
}
Bird.prototype.numLegs = 2; // prototype property
let duck = new Bird(\"Donald\");
duck’s
own
properties to the array ownProps
and prototype
properties to the array prototypeProps
:",
"let ownProps = [];", - "
let prototypeProps = [];
for (let property in duck) {
if(duck.hasOwnProperty(property)) {
ownProps.push(property);
} else {
prototypeProps.push(property);
}
}
console.log(ownProps); // prints [\"name\"]
console.log(prototypeProps); // prints [\"numLegs\"]
own
properties of beagle
to the array ownProps
. Add all of the prototype
properties of Dog
to the array prototypeProps
."
],
"challengeSeed": [
@@ -598,7 +598,7 @@
"The advantage of the constructor
property is that it's possible to check for this property to find out what kind of object it is. Here's an example of how this could be used:",
"function joinBirdFraternity(candidate) {", "Note
if (candidate.constructor === Bird) {
return true;
} else {
return false;
}
}
constructor
property can be overwritten (which will be covered in the next two challenges) it’s generally better to use the instanceof
method to check the type of an object.",
- "joinDogFraternity
function that takes a candidate
parameter and returns true
if the candidate is a Dog
and returns false
otherwise."
],
"challengeSeed": [
@@ -649,7 +649,7 @@
"Bird.prototype.eat = function() {", "A more efficient way is to set the
console.log(\"nom nom nom\");
}
Bird.prototype.describe = function() {
console.log(\"My name is \" + this.name);
}
prototype
to a new object that already contains the properties. This way, the properties are added all at once:",
"Bird.prototype = {", - "
numLegs: 2,
eat: function() {
console.log(\"nom nom nom\");
},
describe = function() {
console.log(\"My name is \" + this.name);
}
};
numLegs
, eat
, and describe
to the prototype
of Dog
by setting the prototype
to a new object. The properties can be set to any values."
],
"challengeSeed": [
@@ -699,7 +699,7 @@
"console.log(duck.constructor)", "To fix this, whenever a prototype is manually set to a new object, remember to define the constructor property:", "
// prints ‘undefined’ - Oops!
Bird.prototype = {", - "
constructor: Bird, // define the constructor property
numLegs: 2,
eat: function() {
console.log(\"nom nom nom\");
},
describe: function() {
console.log(\"My name is \" + this.name);
}
};
Dog
prototype
."
],
"challengeSeed": [
@@ -753,7 +753,7 @@
"function Bird(name) {", "
this.name = name;
}
let duck = new Bird(\"Donald\");
duck
inherits its prototype
from the Bird
constructor function. You can show this relationship with the isPrototypeOf
method:",
"Bird.prototype.isPrototypeOf(duck);", - "
// returns true
isPrototypeOf
to check the prototype
of beagle
."
],
"challengeSeed": [
@@ -806,7 +806,7 @@
"The hasOwnProperty
method is defined in Object.prototype
, which can be accessed by Bird.prototype
, which can then be accessed by duck
. This is an example of the prototype
chain.",
"In this prototype
chain, Bird
is the supertype
for duck
, while duck
is the subtype
. Object
is a supertype
for both Bird
and duck
.",
"Object
is a supertype
for all objects in JavaScript. Therefore, any object can use the hasOwnProperty
method.",
- "function Animal() { };", "Since
Animal.prototype = {
constructor: Animal,
describe: function() {
console.log(\"My name is \" + this.name);
}
};
Animal
includes the describe
method, you can remove it from Bird
and Dog
:",
"Bird.prototype = {", - "
constructor: Bird
};
Dog.prototype = {
constructor: Dog
};
eat
method is repeated in both Cat
and Bear
. Edit the code in the spirit of DRY
by moving the eat
method to the Animal
supertype
."
],
"challengeSeed": [
@@ -934,7 +934,7 @@
"let animal = Object.create(Animal.prototype);", "
Object.create(obj)
creates a new object, and sets obj
as the new object's prototype
. Recall that the prototype
is like the \"recipe\" for creating an object. By setting the prototype
of animal
to be Animal's
prototype
, you are effectively giving the animal
instance the same \"recipe\" as any other instance of Animal
.",
"animal.eat(); // prints \"nom nom nom\"", - "
animal instanceof Animal; // => true
Object.create
to make two instances of Animal
named duck
and beagle
."
],
"challengeSeed": [
@@ -994,7 +994,7 @@
"Remember that the prototype
is like the \"recipe\" for creating an object. In a way, the recipe for Bird
now includes all the key \"ingredients\" from Animal
.",
"let duck = new Bird(\"Donald\");", "
duck.eat(); // prints \"nom nom nom\"
duck
inherits all of Animal's
properties, including the eat
method.",
- "Dog
inherit from Animal
."
],
"challengeSeed": [
@@ -1050,7 +1050,7 @@
"function Bird() { }", "But
Bird.prototype = Object.create(Animal.prototype);
let duck = new Bird();
duck.constructor // function Animal(){...}
duck
and all instances of Bird
should show that they were constructed by Bird
and not Animal
. To do so, you can manually set Bird's
constructor property to the Bird
object:",
"Bird.prototype.constructor = Bird;", - "
duck.constructor // function Bird(){...}
duck.constructor
and beagle.constructor
return their respective constructors."
],
"challengeSeed": [
@@ -1108,7 +1108,7 @@
"Bird.prototype.fly = function() {", "Now instances of
console.log(\"I'm flying!\");
};
Bird
will have both eat()
and fly()
methods:",
"let duck = new Bird();", - "
duck.eat(); // prints \"nom nom nom\"
duck.fly(); // prints \"I'm flying!\"
Dog
object inherits from Animal
and the Dog's
prototype
constructor is set to Dog. Then add a bark()
method to the Dog
object so that beagle
can both eat()
and bark()
. The bark()
method should print \"Woof!\" to the console."
],
"challengeSeed": [
@@ -1177,7 +1177,7 @@
"2. Bird => Is eat() defined here? => Yes. Execute it and stop searching.",
"3. Animal => eat() is also defined, but JavaScript stopped searching before reaching this level.",
"4. Object => JavaScript stopped searching before reaching this level.",
- "fly()
method for Penguin
so that it returns \"Alas, this is a flightless bird.\""
],
"challengeSeed": [
@@ -1237,7 +1237,7 @@
"Here bird
and plane
are passed into flyMixin
, which then assigns the fly
function to each object. Now bird
and plane
can both fly:",
"bird.fly(); // prints \"Flying, wooosh!\"", "Note how the
plane.fly(); // prints \"Flying, wooosh!\"
mixin
allows for the same fly
method to be reused by unrelated objects bird
and plane
.",
- "mixin
named glideMixin
that defines a method named glide
. Then use the glideMixin
to give both bird
and boat
the ability to glide."
],
"challengeSeed": [
@@ -1297,7 +1297,7 @@
"The simplest way to make properties private is by creating a variable within the constructor function. This changes the scope of that variable to be within the constructor function versus available globally. This way, the property can only be accessed and changed by methods also within the constructor function.",
"function Bird() {", "Here
let hatchedEgg = 10; // private property
this.getHatchedEggCount = function() { // publicly available method that a bird object can use
return hatchedEgg;
};
}
let ducky = new Bird();
ducky.getHatchedEggCount(); // returns 10
getHachedEggCount
is a privileged method, because it has access to the private variable hatchedEgg
. This is possible because hatchedEgg
is declared in the same context as getHachedEggCount
. In JavaScript, a function always has access to the context in which it was created. This is called closure
.",
- "weight
is declared in the Bird
function so it is a private variable. Then, create a method getWeight
that returns the value of weight
."
],
"challengeSeed": [
@@ -1342,7 +1342,7 @@
"A common pattern in JavaScript is to execute a function as soon as it is declared:",
"(function () {", "Note that the function has no name and is not stored in a variable. The two parentheses () at the end of the function expression cause it to be immediately executed or invoked. This pattern is known as an
console.log(\"Chirp, chirp!\")
})(); // this is an anonymous function expression that executes right away
// Outputs \"Chirp, chirp!\" immediately
immediately invoked function expression
or IIFE
.",
- "makeNest
and remove its call so instead it's an anonymous immediately invoked function expression
(IIFE
)."
],
"challengeSeed": [
@@ -1390,7 +1390,7 @@
"Note that you have an immediately invoked function expression
(IIFE
) that returns an object motionModule
. This returned object contains all of the mixin
behaviors as properties of the object.",
"The advantage of the module
pattern is that all of the motion behaviors can be packaged into a single object that can then be used by other parts of your code. Here is a example using it:",
"motionModule.glideMixin(duck);", - "
duck.glide();
module
named funModule
to wrap the two mixins
isCuteMixin
and singMixin
. funModule
should return an object."
],
"challengeSeed": [
diff --git a/challenges/02-javascript-algorithms-and-data-structures/regular-expressions.json b/challenges/02-javascript-algorithms-and-data-structures/regular-expressions.json
index a1d1f074d1..0869b1c6b4 100644
--- a/challenges/02-javascript-algorithms-and-data-structures/regular-expressions.json
+++ b/challenges/02-javascript-algorithms-and-data-structures/regular-expressions.json
@@ -42,7 +42,7 @@
"If you want to find the word \"the\"
in the string \"The dog chased the cat\"
, you could use the following regular expression: /the/
. Notice that quote marks are not required within the regular expression.",
"JavaScript has multiple ways to use regexes. One way to test a regex is using the .test()
method. The .test()
method takes the regex, applies it to a string (which is placed inside the parentheses), and returns true
or false
if your pattern finds something or not.",
"let testStr = \"FreeCodeCamp\";", - "
let testRegex = /Code/;
testRegex.test(testStr);
// Returns true
myRegex
on the string myString
using the .test()
method."
],
"challengeSeed": [
@@ -93,7 +93,7 @@
"let testStr = \"Hello, my name is Kevin.\";", "Any other forms of
let testRegex = /Kevin/;
testRegex.test(testStr);
// Returns true
\"the\"
will not match. For example, the regex /the/
will not match \"The\"
or \"THE\"
. A future challenge shows how to match these versions as well.",
"let wrongRegex = /kevin/;", - "
wrongRegex.test(testStr);
// Returns false
waldoRegex
to find \"Waldo\"
in the string waldoIsHiding
with a literal match."
],
"challengeSeed": [
@@ -145,7 +145,7 @@
"This is powerful to search single strings, but it's limited to only one pattern. You can search for multiple patterns using the alternation
or OR
operator: |
.",
"This operator matches patterns either before or after it. For example, if you wanted to match \"yes\"
or \"no\"
, the regex you want is /yes|no/
.",
"You can also search for more than just two patterns. You can do this by adding more patterns with more OR
operators separating them, like /yes|no|maybe/
.",
- "petRegex
to match the pets \"dog\"
, \"cat\"
, \"bird\"
, or \"fish\"
."
],
"challengeSeed": [
@@ -201,7 +201,7 @@
"Case (or sometimes letter case) is the difference between uppercase letters and lowercase letters. Examples of uppercase are \"A\"
, \"B\"
, and \"C\"
. Examples of lowercase are \"a\"
, \"b\"
, and \"c\"
.",
"You can match both cases using what is called a flag. There are other flags but here you'll focus on the flag that ignores case.",
"The flag that ignores case is the i
flag. You can use it by appending it to the regex. An example of using this flag is /ignorecase/i
. This regex can match the strings \"ignorecase\"
, \"igNoreCase\"
, and \"IgnoreCase\"
.",
- "fccRegex
to match \"FreeCodeCamp\"
, no matter its case. Your regex should not match any abbreviations or variations with spaces."
],
"challengeSeed": [
@@ -259,7 +259,7 @@
"So far, you have only been checking if a pattern exists or not within a string. You can also extract the actual matches you found with the .match()
method.",
"To use the .match()
method, apply the method on a string and pass in the regex inside the parentheses. Here's an example:",
"\"Hello, World!\".match(/Hello/);", - "
// Returns [\"Hello\"]
let ourStr = \"Regular expressions\";
let ourRegex = /expressions/;
ourStr.match(ourRegex);
// Returns [\"expressions\"]
.match()
method to extract the word coding
."
],
"challengeSeed": [
@@ -311,7 +311,7 @@
"let testStr = \"Repeat, Repeat, Repeat\";", "To search or extract a pattern more than once, you can use the
let ourRegex = /Repeat/;
testStr.match(ourRegex);
// Returns [\"Repeat\"]
g
flag.",
"let repeatRegex = /Repeat/g;", - "
testStr.match(repeatRegex);
// Returns [\"Repeat\", \"Repeat\", \"Repeat\"]
starRegex
, find and extract both \"Twinkle\"
words from the string twinkleStar
.",
"Note/search/gi
"
],
@@ -364,7 +364,7 @@
"Sometimes you won't (or don't need to) know the exact characters in your patterns. Thinking of all words that match, say, a misspelling would take a long time. Luckily, you can save time using the wildcard character: .
",
"The wildcard character .
will match any one character. The wildcard is also called dot
and period
. You can use the wildcard character just like any other character in the regex. For example, if you wanted to match \"hug\"
, \"huh\"
, \"hut\"
, and \"hum\"
, you can use the regex /hu./
to match all four words.",
"let humStr = \"I'll hum a song\";", - "
let hugStr = \"Bear hug\";
let huRegex = /hu./;
humStr.match(huRegex); // Returns [\"hum\"]
hugStr.match(huRegex); // Returns [\"hug\"]
unRegex
so that it matches the strings \"run\"
, \"sun\"
, \"fun\"
, \"pun\"
, \"nun\"
, and \"bun\"
. Your regex should use the wildcard character."
],
"challengeSeed": [
@@ -423,7 +423,7 @@
"You can search for a literal pattern with some flexibility with character classes
. Character classes allow you to define a group of characters you wish to match by placing them inside square ([
and ]
) brackets.",
"For example, you want to match \"bag\"
, \"big\"
, and \"bug\"
but not \"bog\"
. You can create the regex /b[aiu]g/
to do this. The [aiu]
is the character class that will only match the characters \"a\"
, \"i\"
, or \"u\"
.",
"let bigStr = \"big\";", - "
let bagStr = \"bag\";
let bugStr = \"bug\";
let bogStr = \"bog\";
let bgRegex = /b[aiu]g/;
bigStr.match(bgRegex); // Returns [\"big\"]
bagStr.match(bgRegex); // Returns [\"bag\"]
bugStr.match(bgRegex); // Returns [\"bug\"]
bogStr.match(bgRegex); // Returns null
a
, e
, i
, o
, u
) in your regex vowelRegex
to count the number of vowels in the string quoteSample
.",
"Notecharacter set
, you can define a range of characters to match using a hyphen
character: -
.",
"For example, to match lowercase letters a
through e
you would use [a-e]
.",
"let catStr = \"cat\";", - "
let batStr = \"bat\";
let matStr = \"mat\";
let bgRegex = /[a-e]at/;
catStr.match(bgRegex); // Returns [\"cat\"]
batStr.match(bgRegex); // Returns [\"bat\"]
matStr.match(bgRegex); // Returns null
quoteSample
.",
"Note/[0-5]/
matches any number between 0
and 5
, including the 0
and 5
.",
"Also, it is possible to combine a range of letters and numbers in a single character set.",
"let jennyStr = \"Jenny8675309\";", - "
let myRegex = /[a-z0-9]/ig;
jennyStr.match(myRegex); // matches all letters and numbers in jennyStr
h
and s
, and a range of numbers between 2
and 6
. Remember to include the appropriate flags in the regex."
],
"challengeSeed": [
@@ -582,7 +582,7 @@
"So far, you have created a set of characters that you want to match, but you could also create a set of characters that you do not want to match. These types of character sets are called negated character sets
.",
"To create a negated character set
, you place a caret
character (^
) after the opening bracket and before the characters you do not want to match.",
"For example, /[^aeiou]/gi
matches all characters that are not a vowel. Note that characters like .
, !
, [
, @
, /
and white space are matched - the negated vowel character set only excludes the vowel characters.",
- "+
character to check if that is the case. Remember, the character or pattern has to be present consecutively. That is, the character has to repeat one after the other.",
"For example, /a+/g
would find one match in \"abc\"
and return [\"a\"]
. It would also find one match in \"aabc\"
and return [\"aa\"]
. If it were checking the string \"abab\"
, it would find two matches and return [\"a\", \"a\"]
because the a
characters are not in a row - there is a b
between them. Finally, since there is no \"a\"
in the string \"bcd\"
, it wouldn't find a match.",
- "s
occurs one or more times in \"Mississippi\"
. Write a regex that uses the +
sign."
],
"challengeSeed": [
@@ -684,7 +684,7 @@
"The last challenge used the plus +
sign to look for characters that occur one or more times. There's also an option that matches characters that occur zero or more times.",
"The character to do this is the asterisk
or star
: *
.",
"let sWord1 = \"seed\";", - "
let sWord2 = \"saw\";
let kWord = \"kite\";
let sRegex = /s.*/; // Searches for words starting with s
sRegex.test(sWord1); // Returns true
sRegex.test(sWord2); // Returns true
sRegex.test(kWord); // Returns false
starWarsRegex
that uses the *
character to match all the movie titles that start with \"Star Wars\"
. Your regex does not need flags."
],
"challengeSeed": [
@@ -741,7 +741,7 @@
"You can apply the regex /t[a-z]*i/
to the string \"titanic\"
. This regex is basically a pattern that starts with t
, ends with i
, and has some letters in between.",
"Regular expressions are by default greedy
, so the match would return [\"titani\"]. It finds the largest sub-string possible to fit the pattern.",
"However, you can use the ?
character to change it to lazy
matching. \"titanic\"
matched against the adjusted regex of /t[a-z]*?i/
returns [\"ti\"]
.",
- "Instructions
",
+ "
",
"Fix the regex /<.*>/
to return the HTML tag <h1>
and not the text \"<h1>Winter is coming</h1>\"
. Remember the wildcard .
in a regular expression matches any character."
],
"challengeSeed": [
@@ -793,7 +793,7 @@
"\"z\"
\"zzzzzz\"
\"ABCzzzz\"
\"zzzzABC\"
\"abczzzzzzzzzzzzzzzzzzzzzabc\"
",
"But it does not find matches in the following strings since there are no letter z
characters:",
"\"\"
\"ABC\"
\"abcabc\"
",
- "Instructions
",
+ "
",
"Write a greedy
regex that finds one or more criminals within a group of other people. A criminal is represented by the capital letter C
."
],
"challengeSeed": [
@@ -852,7 +852,7 @@
"Prior challenges showed that regular expressions can be used to look for a number of matches. They are also used to search for patterns in specific positions in strings.",
"In an earlier challenge, you used the caret
character (^
) inside a character set
to create a negated character set
in the form [^thingsThatWillNotBeMatched]
. Outside of a character set
, the caret
is used to search for patterns at the beginning of strings.",
"let firstString = \"Ricky is first and can be found.\";
let firstRegex = /^Ricky/;
firstRegex.test(firstString);
// Returns true
let notFirst = \"You can't find Ricky now.\";
firstRegex.test(notFirst);
// Returns false
",
- "Instructions
",
+ "
",
"Use the caret
character in a regex to find \"Cal\"
only in the beginning of the string rickyAndCal
."
],
"challengeSeed": [
@@ -904,7 +904,7 @@
"In the last challenge, you learned to use the caret
character to search for patterns at the beginning of strings. There is also a way to search for patterns at the end of strings.",
"You can search the end of strings using the dollar sign
character $
at the end of the regex.",
"let theEnding = \"This is a never ending story\";
let storyRegex = /story$/;
storyRegex.test(theEnding);
// Returns true
let noEnding = \"Sometimes a story will have to end\";
storyRegex.test(noEnding);
// Returns false
",
- "Instructions
",
+ "
",
"Use the anchor character ($
) to match the string \"caboose\"
at the end of the string caboose
."
],
"challengeSeed": [
@@ -956,7 +956,7 @@
"The closest character class in JavaScript to match the alphabet is \\w
. This shortcut is equal to [A-Za-z0-9_]
. This character class matches upper and lowercase letters plus numbers. Note, this character class also includes the underscore character (_
).",
"let longHand = /[A-Za-z0-9_]+/;
let shortHand = /\\w+/;
let numbers = \"42\";
let varNames = \"important_var\";
longHand.test(numbers); // Returns true
shortHand.test(numbers); // Returns true
longHand.test(varNames); // Returns true
shortHand.test(varNames); // Returns true
",
"These shortcut character classes are also known as shorthand character classes
.",
- "Instructions
",
+ "
",
"Use the shorthand character class \\w
to count the number of alphanumeric characters in various quotes and strings."
],
"challengeSeed": [
@@ -1010,7 +1010,7 @@
"You've learned that you can use a shortcut to match alphanumerics [A-Za-z0-9_]
using \\w
. A natural pattern you might want to search for is the opposite of alphanumerics.",
"You can search for the opposite of the \\w
with \\W
. Note, the opposite pattern uses a capital letter. This shortcut is the same as [^A-Za-z0-9_]
.",
"let shortHand = /\\W/;
let numbers = \"42%\";
let sentence = \"Coding!\";
numbers.match(shortHand); // Returns [\"%\"]
sentence.match(shortHand); // Returns [\"!\"]
",
- "Instructions
",
+ "
",
"Use the shorthand character class \\W
to count the number of non-alphanumeric characters in various quotes and strings."
],
"challengeSeed": [
@@ -1062,7 +1062,7 @@
"description": [
"You've learned shortcuts for common string patterns like alphanumerics. Another common pattern is looking for just digits or numbers.",
"The shortcut to look for digit characters is \\d
, with a lowercase d
. This is equal to the character class [0-9]
, which looks for a single character of any number between zero and nine.",
- "Instructions
",
+ "
",
"Use the shorthand character class \\d
to count how many digits are in movie titles. Written out numbers (\"six\" instead of 6) do not count."
],
"challengeSeed": [
@@ -1117,7 +1117,7 @@
"description": [
"The last challenge showed how to search for digits using the shortcut \\d
with a lowercase d
. You can also search for non-digits using a similar shortcut that uses an uppercase D
instead.",
"The shortcut to look for non-digit characters is \\D
. This is equal to the character class [^0-9]
, which looks for a single character that is not a number between zero and nine.",
- "Instructions
",
+ "
",
"Use the shorthand character class for non-digits \\D
to count how many non-digits are in movie titles."
],
"challengeSeed": [
@@ -1175,7 +1175,7 @@
"1) The only numbers in the username have to be at the end. There can be zero or more of them at the end.",
"2) Username letters can be lowercase and uppercase.",
"3) Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.",
- "Instructions
",
+ "
",
"Change the regex userCheck
to fit the constraints listed above."
],
"challengeSeed": [
@@ -1229,7 +1229,7 @@
"The challenges so far have covered matching letters of the alphabet and numbers. You can also match the whitespace or spaces between letters.",
"You can search for whitespace using \\s
, which is a lowercase s
. This pattern not only matches whitespace, but also carriage return, tab, form feed, and new line characters. You can think of it as similar to the character class [ \\r\\t\\f\\n\\v]
.",
"let whiteSpace = \"Whitespace. Whitespace everywhere!\"
let spaceRegex = /\\s/g;
whiteSpace.match(spaceRegex);
// Returns [\" \", \" \"]
",
- "Instructions
",
+ "
",
"Change the regex countWhiteSpace
to look for multiple whitespace characters in a string."
],
"challengeSeed": [
@@ -1281,7 +1281,7 @@
"You learned about searching for whitespace using \\s
, with a lowercase s
. You can also search for everything except whitespace.",
"Search for non-whitespace using \\S
, which is an uppercase s
. This pattern will not match whitespace, carriage return, tab, form feed, and new line characters. You can think of it being similar to the character class [^ \\r\\t\\f\\n\\v]
.",
"let whiteSpace = \"Whitespace. Whitespace everywhere!\"
let nonSpaceRegex = /\\S/g;
whiteSpace.match(nonSpaceRegex).length; // Returns 32
",
- "Instructions
",
+ "
",
"Change the regex countNonWhiteSpace
to look for multiple non-whitespace characters in a string."
],
"challengeSeed": [
@@ -1334,7 +1334,7 @@
"You can specify the lower and upper number of patterns with quantity specifiers
. Quantity specifiers are used with curly brackets ({
and }
). You put two numbers between the curly brackets - for the lower and upper number of patterns.",
"For example, to match only the letter a
appearing between 3
and 5
times in the string \"ah\"
, your regex would be /a{3,5}h/
.",
"let A4 = \"aaaah\";
let A2 = \"aah\";
let multipleA = /a{3,5}h/;
multipleA.test(A4); // Returns true
multipleA.test(A2); // Returns false
",
- "Instructions
",
+ "
",
"Change the regex ohRegex
to match only 3
to 6
letter h
's in the word \"Oh no\"
."
],
"challengeSeed": [
@@ -1390,7 +1390,7 @@
"To only specify the lower number of patterns, keep the first number followed by a comma.",
"For example, to match only the string \"hah\"
with the letter a
appearing at least 3
times, your regex would be /ha{3,}h/
.",
"let A4 = \"haaaah\";
let A2 = \"haah\";
let A100 = \"h\" + \"a\".repeat(100) + \"h\";
let multipleA = /ha{3,}h/;
multipleA.test(A4); // Returns true
multipleA.test(A2); // Returns false
multipleA.test(A100); // Returns true
",
- "Instructions
",
+ "
",
"Change the regex haRegex
to match the word \"Hazzah\"
only when it has four or more letter z
's."
],
"challengeSeed": [
@@ -1446,7 +1446,7 @@
"To specify a certain number of patterns, just have that one number between the curly brackets.",
"For example, to match only the word \"hah\"
with the letter a
3
times, your regex would be /ha{3}h/
.",
"let A4 = \"haaaah\";
let A3 = \"haaah\";
let A100 = \"h\" + \"a\".repeat(100) + \"h\";
let multipleHA = /a{3}h/;
multipleHA.test(A4); // Returns false
multipleHA.test(A3); // Returns true
multipleHA.test(A100); // Returns false
",
- "Instructions
",
+ "
",
"Change the regex timRegex
to match the word \"Timber\"
only when it has four letter m
's."
],
"challengeSeed": [
@@ -1501,7 +1501,7 @@
"You can specify the possible existence of an element with a question mark, ?
. This checks for zero or one of the preceding element. You can think of this symbol as saying the previous element is optional.",
"For example, there are slight differences in American and British English and you can use the question mark to match both spellings.",
"let american = \"color\";
let british = \"colour\";
let rainbowRegex= /colou?r/;
rainbowRegex.test(american); // Returns true
rainbowRegex.test(british); // Returns true
",
- "Instructions
",
+ "
",
"Change the regex favRegex
to match both the American English (favorite) and the British English (favourite) version of the word."
],
"challengeSeed": [
@@ -1558,7 +1558,7 @@
"let quit = \"qu\";
let noquit = \"qt\";
let quRegex= /q(?=u)/;
let qRegex = /q(?!u)/;
quit.match(quRegex); // Returns [\"q\"]
noquit.match(qRegex); // Returns [\"q\"]
",
"A more practical use of lookaheads
is to check two or more patterns in one string. Here is a (naively) simple password checker that looks for between 3 and 6 characters and at least one number:",
"let password = \"abc123\";
let checkPass = /(?=\\w{3,6})(?=\\D*\\d)/;
checkPass.test(password); // Returns true
",
- "Instructions
",
+ "
",
"Use lookaheads
in the pwRegex
to match passwords that are greater than 5 characters long and have two consecutive digits."
],
"challengeSeed": [
@@ -1616,7 +1616,7 @@
"The example below matches any word that occurs twice separated by a space:",
"let repeatStr = \"regex regex\";
let repeatRegex = /(\\w+)\\s\\1/;
repeatRegex.test(repeatStr); // Returns true
repeatStr.match(repeatRegex); // Returns [\"regex regex\", \"regex\"]
",
"Using the .match()
method on a string will return an array with the string it matches, along with its capture group.",
- "Instructions
",
+ "
",
"Use capture groups
in reRegex
to match numbers that appear three times in a string each separated by a space."
],
"challengeSeed": [
@@ -1673,7 +1673,7 @@
"let wrongText = \"The sky is silver.\";
let silverRegex = /silver/;
wrongText.replace(silverRegex, \"blue\");
// Returns \"The sky is blue.\"
",
"You can also access capture groups in the replacement string with dollar signs ($
).",
"\"Code Camp\".replace(/(\\w+)\\s(\\w+)/, '$2 $1');
// Returns \"Camp Code\"
",
- "Instructions
",
+ "
",
"Write a regex so that it will search for the string \"good\"
. Then update the replaceText
variable to replace \"good\"
with \"okey-dokey\"
."
],
"challengeSeed": [
@@ -1723,7 +1723,7 @@
"title": "Remove Whitespace from Start and End",
"description": [
"Sometimes whitespace characters around strings are not wanted but are there. Typical processing of strings is to remove the whitespace at the start and end of it.",
- "Instructions
",
+ "
",
"Write a regex and use the appropriate string methods to remove whitespace at the beginning and end of strings.",
"Note
The .trim()
method would work here, but you'll need to complete this challenge using regular expressions."
],
diff --git a/challenges/03-front-end-libraries/sass.json b/challenges/03-front-end-libraries/sass.json
index 96b5d204f0..3d8be455f8 100644
--- a/challenges/03-front-end-libraries/sass.json
+++ b/challenges/03-front-end-libraries/sass.json
@@ -49,7 +49,7 @@
"Here are a couple examples:",
"$main-fonts: Arial, sans-serif;
$headings-color: green;
//To use variables:
h1 {
font-family: $main-fonts;
color: $headings-color;
}
",
"One example where variables are useful is when a number of elements need to be the same color. If that color is changed, the only place to edit the code is the variable value.",
- "Instructions
",
+ "
",
"Create a variable $text-color
and set it to red. Then change the value of the color
property for the .blog-post
and h2
to the $text-color
variable."
],
"challengeSeed": [
@@ -130,7 +130,7 @@
"nav {
background-color: red;
}
nav ul {
list-style: none;
}
li {
display: inline-block;
}
",
"For a large project, the CSS file will have many lines and rules. This is where nesting
can help organize your code by placing child style rules within the respective parent elements:",
"nav {
background-color: red;
ul {
list-style: none;
li {
display: inline-block;
}
}
}
",
- "Instructions
",
+ "
",
"Use the nesting
technique shown above to re-organize the CSS rules for both children of .blog-post
element. For testing purposes, the h1
should come before the p
element."
],
"challengeSeed": [
@@ -205,7 +205,7 @@
"The definition starts with @mixin
followed by a custom name. The parameters (the $x
, $y
, $blur
, and $c
in the example above) are optional.",
"Now any time a box-shadow
rule is needed, only a single line calling the mixin
replaces having to type all the vendor prefixes. A mixin
is called with the @include
directive:",
"div {
@include box-shadow(0px, 0px, 4px, #fff);
}
",
- "Instructions
",
+ "
",
"Write a mixin
for border-radius
and give it a $radius
parameter. It should use all the vendor prefixes from the example. Then use the border-radius
mixin
to give the #awesome
element a border radius of 15px."
],
"challengeSeed": [
@@ -277,7 +277,7 @@
"@mixin make-bold($bool) {
@if $bool == bold { font-weight: bold; }
}
",
"And just like in JavaScript, @else if
and @else
test for more conditions:",
"@mixin text-effect($val) {
@if $val == danger {color: red;}
@else if $val == alert {color: yellow;}
@else if $val == success {color: green;}
@else {color: black;}
}
",
- "Instructions
",
+ "
",
"Create a mixin
called border-stroke
that takes a parameter $val
. The mixin
should check for the following conditions using @if
, @else if
, and @else
:",
"light - 1px solid black
medium - 3px solid black
heavy - 6px solid black
none - no border
"
],
@@ -351,7 +351,7 @@
"The #{$i}
part is the syntax to combine a variable (i
) with text to make a string. When the Sass file is converted to CSS, it looks like this:",
".col-1 {
width: 8.33333%;
}
.col-2 {
width: 16.66667%;
}
...
.col-12 {
width: 100%;
}
",
"This is a powerful way to create a grid layout. Now you have twelve options for column widths available as CSS classes.",
- "Instructions
",
+ "
",
"Write a @for
directive that takes a variable $j
that goes from 1 to 6.",
"It should create 5 classes called .text-1
to .text-5
where each has a font-size
set to 10px multiplied by the index."
],
@@ -425,7 +425,7 @@
"Note that the $key
variable is needed to reference the keys in the map. Otherwise, the compiled CSS would have color1
, color2
... in it.",
"Both of the above code examples are converted into the following CSS:",
".blue-text {
color: blue;
}
.red-text {
color: red;
}
.green-text {
color: green;
}
",
- "Instructions
",
+ "
",
"Write an @each
directive that goes through a list: blue, black, red
and assigns each variable to a .color-bg
class, where the \"color\" part changes for each item.",
"Each class should set the background-color
the respective color."
],
@@ -496,7 +496,7 @@
"$x: 1;
@while $x < 13 {
.col-#{$x} { width: 100%/12 * $x;}
$x: $x + 1;
}
",
"First, define a variable $x
and set it to 1. Next, use the @while
directive to create the grid system while $x
is less than 13.",
"After setting the CSS rule for width
, $x
is incremented by 1 to avoid an infinite loop.",
- "Instructions
",
+ "
",
"Use @while
to create a series of classes with different font-sizes
.",
"There should be 10 different classes from text-1
to text-10
. Then set font-size
to 5px multiplied by the current index number. Make sure to avoid an infinite loop!"
],
@@ -579,7 +579,7 @@
"For example, if all your mixins
are saved in a partial
named \"_mixins.scss\", and they are needed in the \"main.scss\" file, this is how to use them in the main file:",
"// In the main.scss file
@import 'mixins'
",
"Note that the underscore is not needed in the import
statement - Sass understands it is a partial
. Once a partial
is imported into a file, all variables, mixins
, and other code are available to use.",
- "Instructions
",
+ "
",
"Write an @import
statement to import a partial
named _variables.scss
into the main.scss file."
],
"challengeSeed": [
@@ -641,7 +641,7 @@
"The extend
directive is a simple way to reuse the rules written for one element, then add more for another:",
".big-panel{
@extend .panel;
width: 150px;
font-size: 2em;
}
",
"The .big-panel
will have the same properties as .panel
in addition to the new styles.",
- "Instructions
",
+ "
",
"Make a class .info-important
that extends .info
and also has a background-color
set to magenta."
],
"challengeSeed": [
diff --git a/challenges/04-data-visualization/data-visualization-with-d3.json b/challenges/04-data-visualization/data-visualization-with-d3.json
index 623a3f0f75..9098a00163 100644
--- a/challenges/04-data-visualization/data-visualization-with-d3.json
+++ b/challenges/04-data-visualization/data-visualization-with-d3.json
@@ -53,7 +53,7 @@
"Here's an example that selects an unordered list, appends a list item, and adds text:",
"d3.select(\"ul\")
.append(\"li\")
.text(\"Very important item\");
",
"D3 allows you to chain several methods together with periods to perform a number of actions in a row.",
- "Instructions
",
+ "
",
"Use the select
method to select the body
tag in the document. Then append
an h1
tag to it, and add the text \"Learning D3\" into the h1
element."
],
"challengeSeed": [
@@ -110,7 +110,7 @@
"D3 also has the selectAll()
method to select a group of elements. It returns an array of HTML nodes for all the items in the document that match the input string. Here's an example to select all the anchor tags in a document:",
"const anchors = d3.selectAll(\"a\");
",
"Like the select()
method, selectAll()
supports method chaining, and you can use it with other methods.",
- "Instructions
",
+ "
",
"Select all of the li
tags in the document, and change their text to \"list item\"."
],
"challengeSeed": [
@@ -173,7 +173,7 @@
"Here is an example that selects a ul
element and creates a new list item based on the number of entries in the array:",
"<body>
<ul></ul>
<script>
const dataset = [\"a\", \"b\", \"c\"];
d3.select(\"ul\").selectAll(\"li\")
.data(dataset)
.enter()
.append(\"li\")
.text(\"New item\");
</script>
</body>
",
"It may seem confusing to select elements that don't exist yet. This code is telling D3 to first select the ul
on the page. Next, select all list items, which returns an empty selection. Then the data()
method reviews the dataset and runs the following code three times, once for each item in the array. The enter()
method sees there are no li
elements on the page, but it needs 3 (one for each piece of data in dataset
). New li
elements are appended to the ul
and have the text \"New item\".",
- "Instructions
",
+ "
",
"Select the body
node, then select all h2
elements. Have D3 create and append an h2
tag for each item in the dataset
array. The text in the h2
should say \"New Title\". Your code should use the data()
and enter()
methods."
],
"challengeSeed": [
@@ -231,7 +231,7 @@
"The last challenge created a new h2
for each item in the data array, but it displayed the same text (\"New Title\") for each heading. Fortunately, there is a way to access and display the actual data with callback functions.",
"The text()
method can take a string or a callback function as an argument. Since the data from the dataset
array is attached to each element, the callback function has access to it. The parameter used in the callback function (d
in the example below) is for the individual data-point itself. This callback function would set the text in the selection to the data value:",
"selection.text((d) => d)
",
- "Instructions
",
+ "
",
"Change the text()
method so it does not place \"New Title\" in each heading. Instead, it displays the data from the array with a space and \"USD\". For example, the first heading should say \"12 USD\"."
],
"challengeSeed": [
@@ -297,7 +297,7 @@
"D3 lets you add inline CSS styles on dynamic elements with the style()
method.",
"The style()
method takes a comma-separated key-value pair as an argument. Here's an example to set the selection's text color to blue:",
"selection.style(\"color\",\"blue\");
",
- "Instructions
",
+ "
",
"Add the style()
method to the code in the editor to make all the displayed text have a font-family
of verdana
."
],
"challengeSeed": [
@@ -358,7 +358,7 @@
"For example, you may want to color a data point blue if has a value less than 20, and red otherwise. You can use a callback function in the style()
method and include the conditional logic. The callback function uses the d
parameter to represent the data point:",
"selection.style(\"color\", (d) => {
/* Logic that returns the color based on a condition */
});
",
"The style()
method is not limited to setting the color
- it can be used with other CSS properties as well.",
- "Instructions
",
+ "
",
"Add the style()
method to the code in the editor to set the color
of the h2
elements conditionally. Write the callback function so if the data value is less than 20, it returns \"red\", otherwise it returns \"green\".",
"Note
You can use if-else logic, or the ternary operator."
],
@@ -426,7 +426,7 @@
"Using a lot of inline styles on HTML elements gets hard to manage, even for smaller apps. It's easier to add a class to elements and style that class one time using CSS rules. D3 has the attr()
method to add any HTML attribute to an element, including a class name.",
"The attr()
method works the same way that style()
does. It takes comma-separated values, and can use a callback function. Here's an example to add a class of \"container\" to a selection:",
"selection.attr(\"class\", \"container\");
",
- "Instructions
",
+ "
",
"Add the attr()
method to the code in the editor and put a class of bar
on the div
elements."
],
"challengeSeed": [
@@ -495,7 +495,7 @@
"2) Give each div
a dynamic height, using a callback function in the style()
method that sets height equal to the data value",
"Recall the format to set a style using a callback function:",
"selection.style(\"cssProperty\", (d) => d)
",
- "Instructions
",
+ "
",
"Add the style()
method to the code in the editor to set the height
property for each element. Use a callback function to return the value of the data point with the string \"px\" added to it."
],
"challengeSeed": [
@@ -570,7 +570,7 @@
"The last challenge created a bar chart, but there are a couple of formatting changes that could improve it:",
"1) Add space between each bar to visually separate them, which is done by adding a margin to the CSS for the bar
class",
"2) Increase the height of the bars to better show the difference in values, which is done by multiplying the value by a number to scale the height",
- "Instructions
",
+ "
",
"First, add a margin
of 2px to the bar
class in the style
tag. Next, change the callback function in the style()
method so it returns a value 10 times the original data value (plus the \"px\").",
"Note
Multiplying each data point by the same constant only alters the scale. It's like zooming in, and it doesn't change the meaning of the underlying data."
],
@@ -649,7 +649,7 @@
"Here \"scalable\" means that, if you zoom in or out on an object, it would not appear pixelated. It scales with the display system, whether it's on a small mobile screen or a large TV monitor.",
"SVG is used to make common geometric shapes. Since D3 maps data into a visual representation, it uses SVG to create the shapes for the visualization. SVG shapes for a web page must go within an HTML svg
tag.",
"CSS can be scalable when styles use relative units (such as vh
, vw
, or percentages), but using SVG is more flexible to build data visualizations.",
- "Instructions
",
+ "
",
"Add an svg
node to the body
using append()
. Give it a width
attribute of 500 and a height
attribute of 100 using the attr()
method for each. You'll see it in the output because there's a background-color
of pink applied to it in the style
tag.",
"Note
Width and height attributes do not have units. This is the building block of scaling - the element will always have a 5:1 width to height ratio, no matter what the zoom level is."
],
@@ -717,7 +717,7 @@
"When you place a shape into the svg
area, you can specify where it goes with x
and y
coordinates. The origin point of (0, 0) is in the upper-left corner. Positive vales for x
push the shape to the right, and positive values for y
push the shape down from the origin point.",
"To place a shape in the middle of the 500 (width) x 100 (height) svg
from last challenge, the x
coordinate would be 250 and the y
coordinate would be 50.",
"An SVG rect
has four attributes. There are the x
and y
coordinates for where it is placed in the svg
area. It also has a height
and width
to specify the size.",
- "Instructions
",
+ "
",
"Add a rect
shape to the svg
using append()
, and give it a width
attribute of 25 and height
attribute of 100. Also, give the rect
x
and y
attributes each set to 0."
],
"challengeSeed": [
@@ -783,7 +783,7 @@
"A previous challenge showed the format for how to create and append a div
for each item in dataset
:",
"d3.select(\"body\").selectAll(\"div\")
.data(dataset)
.enter()
.append(\"div\")
",
"There are a few differences working with rect
elements instead of divs
. The rects
must be appended to an svg
element, not directly to the body
. Also, you need to tell D3 where to place each rect
within the svg
area. The bar placement will be covered in the next challenge.",
- "Instructions
",
+ "
",
"Use the data()
, enter()
, and append()
methods to create and append a rect
for each item in dataset
. The bars should display all on top of each other, this will be fixed in the next challenge."
],
"challengeSeed": [
@@ -856,7 +856,7 @@
"The attr()
method in D3 accepts a callback function to dynamically set that attribute. The callback function takes two arguments, one for the data point itself (usually d
) and one for the index of the data point in the array. The second argument for the index is optional. Here's the format:",
"selection.attr(\"property\", (d, i) => {
/*
* d is the data point value
* i is the index of the data point in the array
*/
})
",
"It's important to note that you do NOT need to write a for
loop or use forEach()
to iterate over the items in the data set. Recall that the data()
method parses the data set, and any method that's chained after data()
is run once for each item in the data set.",
- "Instructions
",
+ "
",
"Change the x
attribute callback function so it returns the index times 30.",
"Note
Each bar has a width of 25, so increasing each x
value by 30 adds some space between the bars. Any value greater than 25 would work in this example."
],
@@ -935,7 +935,7 @@
"description": [
"The height of each bar can be set to the value of the data point in the array, similar to how the x
value was set dynamically.",
"selection.attr(\"property\", (d, i) => {
/*
* d is the data point value
* i is the index of the data point in the array
*/
})
",
- "Instructions
",
+ "
",
"Change the callback function for the height
attribute to return the data value times 3.",
"Note
Remember that multiplying all data points by the same constant scales the data (like zooming in). It helps to see the differences between bar values in this example."
],
@@ -1017,7 +1017,7 @@
"To make the bars right-side-up, you need to change the way the y
coordinate is calculated. It needs to account for both the height of the bar and the total height of the SVG area.",
"The height of the SVG area is 100. If you have a data point of 0 in the set, you would want the bar to start at the bottom of the SVG area (not the top). To do this, the y
coordinate needs a value of 100. If the data point value were 1, you would start with a y
coordinate of 100 to set the bar at the bottom. Then you need to account for the height of the bar of 1, so the final y
coordinate would be 99.",
"The y
coordinate that is y = heightOfSVG - heightOfBar
would place the bars right-side-up.",
- "Instructions
",
+ "
",
"Change the callback function for the y
attribute to set the bars right-side-up. Remember that the height
of the bar is 3 times the data value d
.",
"Note
In general, the relationship is y = h - m * d
, where m
is the constant that scales the data points."
],
@@ -1096,7 +1096,7 @@
"description": [
"The bars are in the right position, but they are all the same black color. SVG has a way to change the color of the bars.",
"In SVG, a rect
shape is colored with the fill
attribute. It supports hex codes, color names, and rgb values, as well as more complex options like gradients and transparency.",
- "Instructions
",
+ "
",
"Add an attr()
method to set the \"fill\" of all the bars to the color \"navy\"."
],
"challengeSeed": [
@@ -1166,7 +1166,7 @@
"D3 lets you label a graph element, such as a bar, using the SVG text
element.",
"Like the rect
element, a text
element needs to have x
and y
attributes, to place it on the SVG canvas. It also needs to access the data to display those values.",
"D3 gives you a high level of control over how you label your bars.",
- "Instructions
",
+ "
",
"The code in the editor already binds the data to each new text
element. First, append text
nodes to the svg
. Next, add attributes for the x
and y
coordinates. They should be calculated the same way as the rect
ones, except the y
value for the text
should make the label sit 3 units higher than the bar. Finally, use the D3 text()
method to set the label equal to the data point value.",
"Note
For the label to sit higher than the bar, decide if the y
value for the text
should be 3 greater or 3 less than the y
value for the bar."
],
@@ -1249,7 +1249,7 @@
],
"description": [
"D3 methods can add styles to the bar labels. The fill
attribute sets the color of the text for a text
node. The style()
method sets CSS rules for other styles, such as \"font-family\" or \"font-size\".",
- "Instructions
",
+ "
",
"Set the font-size
of the text
elements to 25px, and the color of the text to red."
],
"challengeSeed": [
@@ -1328,7 +1328,7 @@
"description": [
"It's possible to add effects that highlight a bar when the user hovers over it with the mouse. So far, the styling for the rectangles is applied with the built-in D3 and SVG methods, but you can use CSS as well.",
"You set the CSS class on the SVG elements with the attr()
method. Then the :hover
pseudo-class for your new class holds the style rules for any hover effects.",
- "Instructions
",
+ "
",
"Use the attr()
method to add a class of bar
to all the rect
elements. This changes the fill
color of the bar to brown when you mouse over it."
],
"challengeSeed": [
@@ -1412,7 +1412,7 @@
"description": [
"A tooltip shows more information about an item on a page when the user hovers over that item. There are several ways to add a tooltip to a visualization, this challenge uses the SVG title
element.",
"title
pairs with the text()
method to dynamically add data to the bars.",
- "Instructions
",
+ "
",
"Append a title
element under each rect
node. Then call the text()
method with a callback function so the text displays the data value."
],
"challengeSeed": [
@@ -1506,7 +1506,7 @@
"description": [
"A scatter plot is another type of visualization. It usually uses circles to map data points, which have two values each. These values tie to the x
and y
axes, and are used to position the circle in the visualization.",
"SVG has a circle
tag to create the circle shape. It works a lot like the rect
elements you used for the bar chart.",
- "Instructions
",
+ "
",
"Use the data()
, enter()
, and append()
methods to bind dataset
to new circle
elements that are appended to the SVG canvas."
],
"challengeSeed": [
@@ -1583,7 +1583,7 @@
"A circle
in SVG has three main attributes. The cx
and cy
attributes are the coordinates. They tell D3 where to position the center of the shape on the SVG canvas. The radius (r
attribute) gives the size of the circle
.",
"Just like the rect
y
coordinate, the cy
attribute for a circle
is measured from the top of the SVG canvas, not from the bottom.",
"All three attributes can use a callback function to set their values dynamically. Remember that all methods chained after data(dataset)
run once per item in dataset
. The d
parameter in the callback function refers to the current item in dataset
, which is an array for each point. You use bracket notation, like d[0]
, to access the values in that array.",
- "Instructions
",
+ "
",
"Add cx
, cy
, and r
attributes to the circle
elements. The cx
value should be the first number in the array for each item in dataset
. The cy
value should be based off the second number in the array, but make sure to show the chart right-side-up and not inverted. The r
value should be 5 for all circles."
],
"challengeSeed": [
@@ -1674,7 +1674,7 @@
"You can add text to create labels for the points in a scatter plot.",
"The goal is to display the comma-separated values for the first (x
) and second (y
) fields of each item in dataset
.",
"The text
nodes need x
and y
attributes to position it on the SVG canvas. In this challenge, the y
value (which determines height) can use the same value that the circle
uses for its cy
attribute. The x
value can be slightly larger than the cx
value of the circle
, so the label is visible. This will push the label to the right of the plotted point.",
- "Instructions
",
+ "
",
"Label each point on the scatter plot using the text
elements. The text of the label should be the two values separated by a comma and a space. For example, the label for the first point is \"34, 78\". Set the x
attribute so it's 5 units more than the value you used for the cx
attribute on the circle
. Set the y
attribute the same way that's used for the cy
value on the circle
."
],
"challengeSeed": [
@@ -1774,7 +1774,7 @@
"D3 has several scale types. For a linear scale (usually used with quantitative data), there is the D3 method scaleLinear()
:",
" const scale = d3.scaleLinear()
",
"By default, a scale uses the identity relationship. The value of the input is the same as the value of the output. A separate challenge covers how to change this.",
- "Instructions
",
+ "
",
"Change the scale
variable to create a linear scale. Then set the output
variable to the scale called with an input argument of 50."
],
"challengeSeed": [
@@ -1837,7 +1837,7 @@
"The domain()
and range()
methods set these values for the scale. Both methods take an array of at least two elements as an argument. Here's an example:",
"// Set a domain
// The domain covers the set of input values
scale.domain([50, 480]);
// Set a range
// The range covers the set of output values
scale.range([10, 500]);
scale(50) // Returns 10
scale(480) // Returns 500
scale(325) // Returns 323.37
scale(750) // Returns 807.67
d3.scaleLinear()
",
"Notice that the scale uses the linear relationship between the domain and range values to figure out what the output should be for a given number. The minimum value in the domain (50) maps to the minimum value (10) in the range.",
- "Instructions
",
+ "
",
"Create a scale and set its domain to [250, 500]
and range to [10, 150]
.",
"Note
You can chain the domain()
and range()
methods onto the scale
variable."
],
@@ -1904,7 +1904,7 @@
"Fortunately, both the min()
and max()
methods take a callback function.",
"In this example, the callback function's argument d
is for the current inner array. The callback needs to return the element from the inner array (the x or y value) over which you want to compute the maximum or minimum. Here's an example for how to find the min and max values with an array of arrays:",
"const locationData = [[1, 7],[6, 3],[8, 3]];
// Returns the smallest number out of the first elements
const minX = d3.min(locationData, (d) => d[0]);
// minX compared 1, 6, and 8 and is set to 1
",
- "Instructions
",
+ "
",
"The positionData
variable holds a 3-dimensional (3D) array. Use a D3 method to find the maximum value of the z coordinate (the third value) from the arrays and save it in the output
variable.",
"Note
Fun fact - D3 can plot 3D arrays."
],
@@ -1966,7 +1966,7 @@
"In the example, the domain goes from 0 to the maximum in the set. It uses the max()
method with a callback function based on the x values in the arrays. The range uses the SVG canvas' width (w
), but it includes some padding, too. This puts space between the scatter plot dots and the edge of the SVG canvas.",
"const dataset = [
[ 34, 78 ],
[ 109, 280 ],
[ 310, 120 ],
[ 79, 411 ],
[ 420, 220 ],
[ 233, 145 ],
[ 333, 96 ],
[ 222, 333 ],
[ 78, 320 ],
[ 21, 123 ]
];
const w = 500;
const h = 500;
// Padding between the SVG canvas boundary and the plot
const padding = 30;
const xScale = d3.scaleLinear()
.domain([0, d3.max(dataset, (d) => d[0])])
.range([padding, w - padding]);
",
"The padding may be confusing at first. Picture the x-axis as a horizontal line from 0 to 500 (the width value for the SVG canvas). Including the padding in the range()
method forces the plot to start at 30 along that line (instead of 0), and end at 470 (instead of 500).",
- "Instructions
",
+ "
",
"Use the yScale
variable to create a linear y-axis scale. The domain should start at zero and go to the maximum y value in the set. The range should use the SVG height (h
) and include padding.",
"Note
Remember to keep the plot right-side-up. When you set the range for the y coordinates, the higher value (height less padding) is the first argument, and the lower value is the second argument."
],
@@ -2053,7 +2053,7 @@
"You set the coordinate attribute values for an SVG shape with the scaling function. This includes x
and y
attributes for rect
or text
elements, or cx
and cy
for circles
. Here's an example:",
"shape
.attr(\"x\", (d) => xScale(d[0]))
",
"Scales set shape coordinate attributes to place the data points onto the SVG canvas. You don't need to apply scales when you display the actual data value, for example, in the text()
method for a tooltip or label.",
- "Instructions
",
+ "
",
"Use xScale
and yScale
to position both the circle
and text
shapes onto the SVG canvas. For the circles
, apply the scales to set the cx
and cy
attributes. Give them a radius of 5 units, too.",
"For the text
elements, apply the scales to set the x
and y
attributes. The labels should be offset to the right of the dots. To do this, add 10 units to the x data value before passing it to the xScale
."
],
@@ -2180,7 +2180,7 @@
"const xAxis = d3.axisBottom(xScale);
svg.append(\"g\")
.attr(\"transform\", \"translate(0, \" + (h - padding) + \")\")
.call(xAxis);
",
"The above code places the x-axis at the bottom of the SVG canvas. Then it's passed as an argument to the call()
method.",
"The y-axis works is the same way, except the translate
argument is in the form (x, 0). Because translate
is a string in the attr()
method above, you can use concatenation to include variable values for its arguments.",
- "Instructions
",
+ "
",
"The scatter plot now has an x-axis. Create a y-axis in a variable named yAxis
using the axisLeft()
method. Then render the axis using a g
element. Make sure to use a transform
attribute to translate the axis by the amount of padding units right, and 0 units down. Remember to call()
the axis."
],
"challengeSeed": [
diff --git a/challenges/04-data-visualization/json-apis-and-ajax.json b/challenges/04-data-visualization/json-apis-and-ajax.json
index 1097d10799..90df2296bf 100644
--- a/challenges/04-data-visualization/json-apis-and-ajax.json
+++ b/challenges/04-data-visualization/json-apis-and-ajax.json
@@ -49,7 +49,7 @@
"document.addEventListener('DOMContentLoaded',function() {
});
",
"Next, you can implement a click event handler that goes inside of the DOMContentLoaded
function by adding the following code:",
"document.getElementById('getMessage').onclick=function(){};
",
- "Instructions
",
+ "
",
"Add a click event handler inside of the DOMContentLoaded
function for the element with id of getMessage
."
],
"challengeSeed": [
@@ -132,7 +132,7 @@
"For example, when a user clicks the \"Get Message\" button, it changes the text of the element with the class message
to say \"Here is the message\".",
"This works by adding the following code within the click event:",
"document.getElementsByClassName('message')[0].innerHTML=\"Here is the message\";
",
- "Instructions
",
+ "
",
"Add code inside the onclick
event handler to change the text inside the message
element to say \"Here is the message\"."
],
"challengeSeed": [
@@ -223,7 +223,7 @@
"Here's a review of what each piece is doing. The JavaScript XMLHttpRequest
object has a number of properties and methods that are used to transfer data. First, an instance of the XMLHttpRequest
object is created and saved in the req
variable.",
"Next, the open
method initializes a request - this example is requesting data from an API, therefore is a \"GET\" request. The second argument for open
is the URL of the API you are requesting data from. The third argument is a Boolean value where true
makes it an asynchronous request.",
"The send
method sends the request. Finally, the onload
event handler parses the returned data and applies the JSON.stringify
method to convert the JavaScript object into a string. This string is then inserted as the message text.",
- "Instructions
",
+ "
",
"Update the code to create and send a \"GET\" request to the Free Code Camp Cat Photo API. Then click the \"Get Message\" button. Your Ajax function will replace the \"The message will go here\" text with the raw JSON output from the API."
],
"challengeSeed": [
@@ -320,7 +320,7 @@
"Another interesting \"key-value pair\" in the first object is \"codeNames\":[\"Juggernaut\",\"Mrs. Wallace\",\"ButterCup\"]
. Here \"codeNames\" is the key and its value is an array of three strings. It's possible to have arrays of objects as well as a key with an array as a value.",
"Remember how to access data in arrays and objects. Arrays use bracket notation to access a specific index of an item. Objects use either bracket or dot notation to access the value of a given property. Here's an example that prints the \"altText\" of the first cat photo - note that the parsed JSON data in the editor is saved in a variable called json
:",
"console.log(json[0].altText);
// Prints \"A white cat wearing a green helmet shaped melon on it's head.\"
",
- "Instructions
",
+ "
",
"For the cat with the \"id\" of 2, print to the console the second value in the codeNames
array. You should use bracket and dot notation on the object (which is saved in the variable json
) to access the value."
],
"challengeSeed": [
@@ -413,7 +413,7 @@
"Then, loop through the JSON, adding HTML to the variable that wraps the key names in strong
tags, followed by the value. When the loop is finished, you render it.",
"Here's the code that does this:",
"json.forEach(function(val) { var keys = Object.keys(val); html += \"<div class = 'cat'>\"; keys.forEach(function(key) { html += \"<strong>\" + key + \"</strong>: \" + val[key] + \"<br>\"; }); html += \"</div><br>\";});
",
- "Instructions
",
+ "
",
"Add a forEach
method to loop over the JSON data and create the HTML elements to display it."
],
"challengeSeed": [
@@ -506,7 +506,7 @@
"When you're looping through these objects, you can use this imageLink
property to display this image in an img
element.",
"Here's the code that does this:",
"html += \"<img src = '\" + val.imageLink + \"' \" + \"alt='\" + val.altText + \"'>\";
",
- "Instructions
",
+ "
",
"Add code to use the imageLink
and altText
properties in an img
tag."
],
"challengeSeed": [
@@ -602,7 +602,7 @@
"Given that the JSON data is stored in an array, you can use the filter
method to filter out the cat whose \"id\" key has a value of 1.",
"Here's the code to do this:",
"json = json.filter(function(val) {
return (val.id !== 1);
});
",
- "Instructions
",
+ "
",
"Add code to filter
the json data to remove the cat with the \"id\" value of 1."
],
"challengeSeed": [
@@ -704,7 +704,7 @@
"Here's code that does this:",
"if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position) {
document.getElementById('data').innerHTML=\"latitude: \"+ position.coords.latitude + \"<br>longitude: \" + position.coords.longitude;
});
}
",
"First, it checks if the navigator.geolocation
object exists. If it does, the getCurrentPosition
method on that object is called, which initiates an asynchronous request for the user's position. If the request is successful, the callback function in the method runs. This function accesses the position
object's values for latitude and longitude using dot notation and updates the HTML.",
- "Instructions
",
+ "
",
"Add the example code inside the script
tags to check a user's current location and insert it into the HTML."
],
"challengeSeed": [
@@ -759,7 +759,7 @@
"The setRequestHeader
method sets the value of an HTTP request header, which contains information about the sender and the request. It must be called after the open
method, but before the send
method. The two parameters are the name of the header and the value to set as the body of that header.",
"Next, the onreadystatechange
event listener handles a change in the state of the request. A readyState
of 4 means the operation is complete, and a status
of 200 means it was a successful request. The document's HTML can be updated.",
"Finally, the send
method sends the request with the userName
value, which was given by the user in the input
field.",
- "Instructions
",
+ "
",
"Update the code to create and send a \"POST\" request. Then enter your name in input box and click \"Send Message\". Your Ajax function will replace \"Reply from Server will be here.\" with the reply of the server. In this case, it is your name appended with \" loves cats\"."
],
"challengeSeed": [