Free Code Camp Flashcards

1
Q

what does target=”blank on a link mean?

A

it means that when you click on a link it opens in a new window

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how do you create an internal link to another section of the website?

A

on the href of the a tag…. you add the id of the section you want to go to

a href=#contactsPage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how do wwe comment out in html? (non shortcut)

A

basically two arrows using dashes, the first set gets an exclamation point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how do you make an image a link?

A

nest the img tag inside of an anchor tag

a href >

img src />

/a>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does HTML stand for?

A

Hyper Text Markup Language

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Using the analogy of a body, what is HTML?

A

The bones of the body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

h1 is the first h tag, what is the lowest ?

A

it goes from h1 - h6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of h1 - h6 tags

A

Tells the browser about the structure of your page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

h1 is specifically used for what?

A

Main heading of page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

h2 is specifically used for what?

A

sub headings on page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

h3 - h6 is specifically used for what?

A

for different sections on the page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does every img tag need?

A

an alt tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does an alt tag do? What is the purpose?

A

In the event that a picture doesnt load, the alt tag’s text will be displayed so we will still know what it is.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between an ul and an ol tag? And what do they stand for?

A

The ul, is an unordered list - meaning that the order of the list item doesnt matter. The list items are bulleted.

The ol, is an ordered list - meaning that the order of the list items does matter. The list items are numbered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When do you use an input tag?

A

When you want the user to input information, or you want to gather information from the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type of input do you use when you want the user to enter text?

A

input type =”text”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What do we want to wrap a collection of our inputs in?

A

a form tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What attribute do we want to place on a form tag? And what does its value do?

A

action =

its value tells the form what to do with the information that has been input by the user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How does a form tag know when the user is done entering information inside of the input tags it contains?

A

The best practice is a submit button that a user can click at the end of the form. This will trigger the action attribute on the form tag.

button type=”submit”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the required attribute on an input tag do? And When do we want to use it?

A

It makes an input box required to be filled for the submit button to work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are radio buttons and how do you render them?

A

Radio buttons are for when you want the user to pick only one answer out of a list of choices.

input type=”radio”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What should we always nest our radio and checkboxes inputs in ?

A

a label tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What do label tags do?

A

a label renders the name of the choice to the user so they can see what they are clicking.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What happens if you dont use label tags on checkboxes and radio buttons?

A

The boxes and buttons will have no names for the user so he or she will not be able to make a selection because they wont know what they are actually choosing. It’s pointless without labels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
All radio button inputs must share the same type="radio" and what other attribute?
They must share the same name attribute, this way the page knows that only one of the buttons can be selected at a time. If buttons dont have the same name multiple ones can be selected at the same time, thus defeating the purpose of radio buttons in the first place input type ="radio" name="gender" input type ="radio" name="gender"
26
Whats the difference between radio buttons and checkboxes?
With radio boxes you check one of a group. With checkboxes you can select one or more. Or you can select none
27
All input tags should have at least what four attributes?
type name id {always} value {for react and changing state in react}
28
What is the checked attribute and what type of inputs does it go on?
It sets particular buttons to be already checked by default. The user would have to click it to uncheck it or check another option to change it if it were incorrect. It goes on radio inputs and checkbox inputs
29
What does CSS stand for?
Cascading Style Sheets
30
What is the DOM stand for?
Document Object Model
31
What is Inline Styling?
It is styling an HTML element directly in the HTML line of code.
32
What attribute do we add to the HTML element in order to add inline styling?
style=" "
33
How do we apply the value to a style tag?
style= " name : value " style="color: red"
34
What does the CSS property 'color' do?
It sets the color of the text of an element
35
What is Internal Styling?
It is styling an HTML element inside the HMTL file but not inside of the line. You do it the same way as you would style it externally except that you wrap the styling in a style tag. ``` style > h1 { color: blue } /style> ```
36
What CSS property changes the font?
font-family:
37
What tag and attribute combination do we use to import fonts/stylesheets to our HMTL page?
link href />
38
What is the head tag?
The Head tag is where we place all our meta data about our page, like the stylesheets and fonts and tltles etc. Not the actual content that will be rendered.
39
What is the Title tag?
The Title tag is the name of page. It is the name or the content that shows up on the tab when the page opens. Usually goes along with a logo
40
How do you add multiple fonts to a font-family and why would you do that?
You add a comma between the names of the fonts font-family: helvitica, sans-serif You would do this to basically say....if the first font is there - use that. If not, use the other. If neither is there then your browser will assign a default font.
41
How do we make any border into a perfect circle?
border-radius : 50%
42
What does the CSS property Padding do?
It increases the space between the content of an element and its borders on all sides. p { padding : 20px } this will push the borders on the top, left, right, and bottom away from the paragraph text.
43
What happens if you set the padding of an element 's content to a value less than the established width or height already assigned?
You wont see a difference in appearance. The padding will get bigger still, but you wont see it because it wont actually affect the border at all because the border is already farther out
44
What is the CSS property Margin do?
It increases the space between the border of the element and other elements on the page
45
What is the operating order of Clockwise Notation?
top, right, bottom, left (like a clock)
46
What is the name of setting 4 numeric values to a CSS property like border to an element?
Clockwise Notation.
47
What is Inheritance in CSS?
When an element has no specific styling in regards to a particular aspect of its appearance and adopts or inherits styling from a parent element or grandparent that it is nested in.
48
When you have contradictory styling on a HTML element, which styling is going to get applied?
The more specified element
49
When you have contradictory styling on a HTML element, AND they have the same specificity which styling is going to get applied?
The style rule that is lower on the style-sheet. It gets read in the code last so it gets applied to the DOM last so its the one that you see,
50
If your HTML element has multiple classes with contradictory styling declarations, does the order of these classes in the element code affect which style gets rendered?
No the order of the classes and how they are listed and applied to the element have no bearing on which style gets rendered. In this case, the style that is lower in the style sheet is the one that will get rendered.
51
If you have contradictory styling declarations on an HTML element, lets say one set rules on a class and another on an id , which style will get rendered?
The Id style will get rendered because it is more specific than class
52
When it comes to CSS styling, what overrides any other type of CSS rules being declared on the element?
Inline Styling. Hard coding the element with a style attribute will override any CSS assigned through internal or external stylings.
53
What CSS keyword can you use to get CSS to ignore normal Override Rules and apply a particular CSS declaration?
!important p { color: red !important }
54
When setting a CSS value for any one of the color properties, how does RGB work?
rgb( red, green, blue, transparency)
55
In a RGB value what is the lowest and highest possible values for the Red, Green and Blue values?
0 minimum 255 is the maximum. Theres 256 values all together with the counting beginning at 0.
56
What is the RGB value for the color black?
color: rgb( 0,0,0)
57
What is the RGB value for the color white?
color: rgb(255, 255, 255)
58
Which CSS property do we use to adjust the text of an element?
text-align: example: h1 { text-align: center;
59
What does the CSS value justify do?
Stretches the lines so that each line has equal width (like in newspapers and magazines) except the last line.
60
How do you make something bold text?
By adding a strong text around the text or adding font-weight: bold to it in CSS
61
How do you make something underlined?
use the u tag or text--decoration: underline in CSS
62
How do you make text italicized?
use the em tag or font-style: italic in CSS
63
How do you make text with a line cutting through it (strike-through text?
use the del tag or text-decoration: line-through
64
What does the hr tag do?
Its a self closing tag that creates a horizontal line that goes across the length of its containing element. This is good for sectioning off different topics or sections
65
In RGB, we know that it stands for red, green and blue, but what is the name of the section that controls transparency?
Alpha rgba( 0,0,0,0.1)
66
In RGBA what is the range of possible values for Alpha?
0 - 1 example 0.2
67
When setting Alpha values, which contains the most opacity and which contains the least opacity?
0, is the most - completely see through 1, is the least - not see through at all
68
What does the CSS property Box Shadow do?
It attaches one or more shadows to an element
69
What is the basic syntax for Box Shadow Property?
box-shadow: horizontal offset vertical offset color box-shadow: 5px 5px blue
70
If we want to add multiple shadows to an element how do we do so?
By adding multiple shadow values to an element separated by a comma box-shadow: 5px 5px blue, 10px 10px red, 15px 15px green; this will give us an element with three different and distinct shadows
71
What is the Blur value on Box-Shadow in CSS and where do we set it in the syntax?
The Blue value applies a blurred effect to the shadow of your element. If you want to apply this you would add it after the value for the Vertical Offset. The higher the number the more blurred the shadow. box-shadow: 5px 10px 18px red this would be very blurred; if 18px was changed to 3px the blur effect would decrease significantly
72
What is the Spread value on Box-Shadow in CSS and where do we set in in the syntax?
The Spread value determines how big the shadow of the element is, a positive number increases the shadow. A negative number decreases the shadow. The value will be fourth on the box-shadow property box-shadow: 5px 10px 18px {10px} red
73
If we want to adjust the transparency of an element, but dont need to set a full RGBA property, what CSS property do we use? And what values do we use?
Opacity - And you can set anything from 0.1 to 1.0 .....the higher the number the less see through it will be. The lower the number, the more see through it will be. You can use double digit decimals as well Opacity: 0.25 would set it to 75% opacity.
74
What is the Text-Transform Property in CSS? And what are three values and what do they do?
It adjusts the capitalization of text. lowercase : makes the text lower case uppercase : makes every letter uppercase capitalize : makes the first letter of every word capital.
75
What do you need to add to the value of a Font-Family property in CSS when importing it from a stylesheet as opposed to a ready built in font already known by your browser?
You need to add quotations. {built in fonts} font-family: monospace; {imported fonts] font-family: "Open sans" ;
76
What is Font-Weight in CSS? What are the numeric values? What are the non numeric values?
It sets how think or thin you want the characters of text to be. Numeric Values are set from 100 - 900 900 being more bold, 100 being the the least ____________________________________ Non Numeric Values are : lighter Normal (400) bold (700) bolder
77
What is Line-Height Property in CSS and what is the default setting for most browsers?
The Line-Height property determines how much space there is in between lines. This is the most effective way to adjust how much room a group of text will take up on the page. The default setting for line-height in most browsers is 110% - 120%
78
How can we remove the underline effect on the hyperlinks of your page, or any other underlined element?
text-decoration: none;
79
What is the Hover pseudo-class? What is the syntax to apply it?
It allows a visual effect to take place when the mouse/cursor goes over an element but doesn't click or do anything to activate the element. element : hover { property: value }
80
What is CSS Box Model in a nutshell?
CSS treats each individual element as its own box
81
What is a Block-Level Elements?
It is an element that automatically begin on a new line. Think : paragraphs, divs and headers tags
82
What are Inline-Elements?
They are element that sit on the same line as other elements, and are surrounded by other elements. Think: span, bold, underline, image tags
83
What is Normal Flow of a document?
Displays elements as they are listed on the document, starting from the top left of the page and go straight down to the bottom.
84
What CSS property can we use to take a document out of Normal Flow?
We can use the CSS property Position
85
What does the value of Relative do on the CSS Position property?
It allows you to take an element out of normal flow and move it in relation to its regular position in Normal Flow
86
What CSS properties are used in conjunction with Position: Relative to move the desired element?
left, right, top and bottom values can be pixels or percentages.
87
Does changing an element out of Normal Flow take the whole page out of Normal Flow?
No it doesn't. The rest of the page stays in normal flow. The Position property overrides Normal Flow on that specific element but doesn't change the flow of the page all together.
88
If you can move elements wherever you want using the Position property, does it matter how you write your HTML? People never see it, so what does it matter?
Practicing good Semantic HTML is important even if it doesn't visually represent how the page will look. Mainly because the structure of the page represents the importance of information for screen readers and search engines and allows visually impaired users to successfully navigate and access the desired information on your page.
89
What is the Absolute value for the Position property do?
It locks the element in place relative to the closest positioned ancestor. Usually a parent an usually this is done by declaring position: relative on the parent.
90
What happens if you declare Position: Absolute and its parent isnt a positioned element?
It will keep looking up the chain looking for a positioned element. If it doesn't find one it will default to the body tag.
91
When an element is given Position: Absolute, does it remain in normal flow ?
No, the element is taken out of normal flow and all of the other elements ignore it like it isnt even there.
92
What is the value of Fixed for the CSS property Position?
It is a type of absolute positioning where the element is positioned in relation to the browser window.
93
Are elements that are assigned with the Position of Fixed taken out of Normal Flow?
Yes, they are taken out of Normal Flow and other elements don't realize that the element is there at all
94
What is the main difference between Absolute and Fixed besides its Position relativity?
The Fixed element doesn't move when the user scrolls. It stays in that one spot no matter what the user does.
95
What is the Float property in CSS? And what values does it take?
Floated elements take a value of either Left or Right. This property will take the element and place it either to left or the right of its parent container
96
Which CSS property is often used with Float to adjust how much horizontal space it takes up of the parent element?
It is used with Width.
97
Does Absolutely positioned elements recognized the Float property on other elements?
No, they ignore them.
98
How can you use a Div and the Float property to style the first letter or word of a paragraph?
You can put a div around the first letter, apply Float: left to it to have it stand out from the rest of the paragraph. Apply a class name to the div, then go into CSS and add styling to the class name to enlarge it or make it a different font or color.
99
Do Floated elements remain in Normal Flow?
No they do not, they are taken out of normal flow..so other elements will go along side the left or the right of them if there is space
100
What does the CSS Clear property do?
When an element is given the Float property, it is taken out of Normal Flow meaning that other elements will go along the left or the right of it. This might not be a desired effect. Adding a Clear property will tell the browser to not place any elements along side the element in that direction. note: this only applies to other floated items. so if you want to clear the space both the element and the element you are trying to clear must be floated
101
What are the values of the Clear property in CSS?
Left, Right and Both
102
What is the Z-Index property in CSS?
When elements are positioned to overlap, the element coming later in the HTML markup will by default appear on top of the earlier written elements. Z-Index allows you to specify the order in which these elements overlap
103
How does the specification of elements using Z-Index work?
Every element that is in the overlap stack takes the property Z-Index: with a full number as a value. The element with the highest number will be on top and the element with the lowest number will be on bottom.
104
How can you center a block element horizontally?
by setting its Margin to Auto if there is no other element on the left or the right of it that is in its way, the block element will be centered
105
Images by default are what type of elements?
Inline Elements
106
How do you change an Inline Element to a Block Element?
Display: Block
107
What is Linear-Gradient and what CSS property is it used with?
It is a way to make one color change into another color. It is accessed with the CSS property Background.
108
Since Linear-Gradients have to do with color, can we use them whenever we want to add color somewhere, like text or borders?
No we cannot because Gradient is technically an Image data type, so it can only be used where images can be used. Basically, through the Background property
109
What is the syntax of Linear-Gradient?
Background: Linear-Gradient( gradient direction, color 1, color 2, color 3....)
110
What is Repeating-Linear-Gradient?
Repeating Linear Gradient is like Linear Gradient except that it requires color Start/Stop points other wise it works just like regular linear Gradient. Also, where you place the stop point for the final color will be where the first repetition of the colors will begin. For example (red 0%, blue, yellow50%) would have red start the transition and go to blue and then yellow and this transition would be completed at the halfway mark of the div. Then the transition would start again with Red at 51% and then blue and yellow at 100%, which would be a total of two repetitions of the pattern if you set it as (red0% blue yellow 10%) the entire transition would be complete at 10% and then repeat again and again until the div was taken up, meaning there would be a total of 10 repetitions of the patterns
111
What is the default direction for Gradients?
Top to Bottom
112
What are the directional Gradient values?
``` To Bottom (default) To Right To Left To Top To Top Left To Top Right To Bottom Left To Bottom Right (+/- num)degs ```
113
When you use a Linear Gradient, when does the transition from one color start to take place?
It starts happening right away. The colors will not be pure except for the end and the very beginning
114
Is there a way for you to set where the transition from one color to the next begins to take place when using a Gradient?
Yes, you can add a percentage or a px value after the name or assignment of the color to say basically : "start transitioning here" linear-gradient( red 25%, blue) this will keep red pure all the way until it reaches 25% of the container and then start transitioning to blue along the remaining 75% until it reaches pure blue at the end
115
What is Radial-Gradient?
It is the same as Linear-Gradient, but it goes in a circle instead of in one direction
116
What happens if you set the end of a color in the same place as a beginning of a color using a Gradient?
There will be no transition, the colors will just have a clean break with a switch from one color to the next linear-gradient( red 50%, blue 50%) in the middle of the page, the colors will switch from red to blue with no transition
117
When adding color starts and stops, how many values can you place per color?
Two - a start and a stop (red 35% 50%) this would make the color red go from 35% of the element - half way through the element.
118
Do the first and last colors in a Gradient need to have both start and stop places specified?
No, the first color will start at 0% by default so only the stop place is required. The last color will automatically stop at 100% so only the start place is required. (red 25%, blue 25% 50&, yellow 50% 75%, orange 75% ) red is already starting at zero orange is already stopping at 100 so additional start and stop values arent needed. Blue and yellow are in the middle, so where they start and stop need to be added if you want to specify where the transition starts and stops
119
How do we add a Background Image to an element?
background-image: url(' ')
120
What does the value Scale do on the Transform CSS property? And what is the syntax?
It allows you to increase the size of your image or image like element. The number you put in the parenthasis is the amount of times larger the element compared to its normal, or currently set size. transform: scale(3) this will make a picture or image like element three times as big as it currently is
121
What does the SkewX and SkewY value do on the CSS property Transform? What is the syntax?
It skews the edges diagonally along the X or Y axis. transform: skewX(23deg)
122
What do the pseudo elements :Before and :After do?
They target or set what comes before or after an element. For example of a list element li : before { content: "this is a list item" } This would make the string this is a list item come before every list item on the page
123
What is the Animation-Name and Animation-Duration CSS properties? Where are they placed?
They describe the name of the animation and how long it will take to complete or to run the entire animation. These are placed inside of the elements CSS rule set. h1 { animation-name: changeColors; animation-duration: 10s; }
124
How do you we set what actually happens in the animation after we have set it on a particular element in CSS?
``` We use @keyframes animation-name { length of time { what we actually want to happen } } ``` ``` @keyframes changeColor { 0% { background-color: red } 50% { background-color: black; } } ``` This will start the back ground color at red....this would last for 5 seconds ( if we set the animation duration for 10 seconds) and then it would turn black.
125
What are some popular times to use Animation to change colors or add different effects like slightly enlarging the size of an element?
During Hover's or button onclicks
126
What is Animation-Fill-Mode: Forwards in CSS and why do we use it?
When we set an animation, at the end of the duration, it reverts back to its original state and will run again once the code is called again. Animation-Fill-Mode: Forwards sets it up so the element stays at the final stage as long as what triggered the animation is still true. for example, if a page load triggers the animation, then the final animation stage will remain visible because the page is still loaded and will not reset until the page is loaded again. if Hover triggers the animation, then animation will remain in the final stage as long as Hover is still being utilized. Once you move your mouse, the original animation stage will take back over and will refire once Hover is reapplied.
127
Can you use Animation Rules to create movement of elements on a page?
Yes you can, as long as an element has a specified position like relative or fixed. The CSS offset properties like left/right can be used to create animation movement. This is an example of @keyframes moving an element up and then down while changing the color. ``` @keyframes rainbow { 0% { background-color: blue; top: 0px; } 50% { background-color: green; top: 50px; } 100% { background-color: yellow; top: 0px; } } ```
128
What is the CSS property Animation-Iteration-Count? Which values can it take?
This property sets how many consecutive times your animation will run. You can set it to a specific number or you can set it to infinite and the animation will keep running. animation-iteration-count: 3 animation-iteration-count: infinite
129
What is a good styling tip to keep in mind about your Animated elements?
You can change their size movements, colors and durations and how many times they run independent of one another. They dont need to all share the same rules so that they have a uniform look....sometimes its good to give them their own independent life so it looks more interactive and lifelike and less robotic. think of the twinkling stars challenge
130
What is the Animation-Timing-Function property in CSS? What is a good mental model to have about it so it doesnt get confused with Animation-Duration?
Animation Duration is the overall road trip. SF to NY. This is the total ground that needs to be covered. We can set this to 5 seconds. This is how long the trip is from A - B. Animation-Timing-Function is how that trip is travelled. The distance from SF to NY will still be the same and take the same amount of time, but do you speed first through the western states and slow down and take your time in teh eastern states? Or do you take your time and sight see in the western states and speed through the eastern states to get to your destination? Or do you just take a nice steady course, nice and easy all the way through? Animation-Timing-Function determines this mode of travel.
131
What is the default value for Animation-Timing-Function whether set or not? What does this value mean?
Ease. start slow, speed up in the middle, slows down again in the end.
132
What is the Ease-Out/Ease-In value on the CSS Animation-Timing-Function property?
Ease-Out: Quick start. Slow End. Ease-In: Slow start. Fast End
133
What is the Linear value on the CSS Animation-Timing-Function property?
This applies a constant animation speed throughout the course of the animation duration.
134
What does Accessibility refer to, when being discussed in the context of Web Development?
means having web content and a user interface that can be understood, navigated, and interacted with by a broad audience. This includes people with visual, auditory, mobility or cognitive disabilities
135
Why is an ALT tag important for search engines?
Alt tags are used by search engines to index what is in a photo so it can return related images to a search.
136
Why is an ALT tag important for visually impaired users? If they can't see the image or the text, why would an ALT tag help them at all?
The ALT tag is also read by screen readers so people who cant see can be told what is in an image audibly
137
What are some times where you would want to add an EMPTY STRING to an ALT tag of an IMG? What are some examples of this?
Photos that are used for decoration only and dont add any meaning to the content or to the page itself. examples of this would be background images for decoration purposes.
138
If an IMG already has a caption in its content explaining what it is - should you use an ALT with a string or an ALT without a string?
It is possible to use an ALT without a string even the caption would be redundant because of the caption. But i would opt to use one because of the screen readers and because the alt tag is used to index photos in search engines.
139
How many times should you use H1 on a page?
once.
140
There are H1 - H6, should you pick H#'s by their size and how they look?
No you shouldn't. Choose them by relevancy of their content. H2's should be a sub section of H1 H3's should be sub sections of H2's H4's should be sub sections of H3's and so on and so forth
141
Why is important for your H#'s to have Semantic Meaning and relate to one another?
Some screen readers can be set to read only the headings on a page so the user gets a summary of the page. Its important that your headings facilitate this for the users.
142
Should you skip H#'s ? Like if you have an H1 should you jump straight to an H5?
No, this confuses screen readers. You should order your content one header at a time. Its ok to not use certain headers, but if you do use them, you shouldnt skip them.
143
What is the MAIN tag and how many should there be on the page? Using this tag allows for what functionality?
It wraps the main content of a page, shouldnt include repeating content like nav bars etc. There should be one per page. Assistive technologies allow a "Jump to Main Content" link that takes users to the main content of a page.
144
What is the Article tag and what is it used for Semantically?
Used to group independant, self contained content. Content that can be understood outside of the context of other content. Think of an article as a book
145
What is the Section tag and what is it used for Semantically?
Used to group thematically related content . These can be used inside of Article tags. If the Article tag is a book, then the Section tag would be the chapters.
146
What is the Div tag and what is it used for Semantically?
It is used to group content when there is no relationship between groups of content
147
What is the Header tag? And why do we use it? Using this tag allows for what functionality?
It is used to wrap introductory information or navigation links for its parent tag and works well around content thats repeated at the top of multiple pages. Header tag allows assistive technologies to quickly navigate to that content.
148
What is the Nav tag and what is it used for? What functionality does using this tag afford?
This tag is meant to wrap around the main navigation link in your page. This tag allows for easy screen reading navigation.
149
If the links in the Nav bar are repeated at the bottom of the page, is a second Nav tag necessary?
No, a second Nav tag isnt necessary. A Footer tag will do just fine.
150
What does the Footer tag do? What functionality does it afford?
It wraps information about copyright or links related to documents that usually sit at the bottom of the page. This has built in Landmark features that allow easy navigation to this section using assistive technologies
151
What is a Boolean Attribute?
Its an attribute that doesnt need a value. Its presence turns the feature on. for example checked, required etc.
152
What is the Audio tag? What is it used for? What is the syntax?
It is used to add audio to your webpage audio controls src="audio.mp3">/audio
153
What does the Boolean Attribute 'Controls' do?
It brings up media controls for audio/video that allows you to play/pause the media file amongst other things.
154
Audio and other type of media also should include what?
A text component along with a visual component to accessible to people who are deaf or hard of hearing
155
What is the tag Figure and Figcaption tag and what are they used for? What is the syntax?
These tags are used together to wrap a visual representation like a chart or an image along with its caption. The figcaption tag can be used to give the conclusion or findings represented by a chart. ``` figure> img src alt > figcaption > This Chart says you broke /figcaption> /figure> ```
156
How do we use the For attribute on a Label tag?
The value of 'For' attribute on the label tag should be the same as the value of the Name or ID attribute on the input tag thats wrapped in it. label for="email"> input type=text name=email> /label>
157
What is the Fieldset tag? What default styling does it come with?
A fieldset tag groups a bunch of inputs - radio buttons for example. This sections off the whole are where the user is to put in inputs It has a default styling of a box around whatever is nested inside of its tags...this default styling can be changed in css
158
What is the Legend tag?
The legend tag is the name of a section of related inputs. ``` form> fieldset> legend> Whats your fav sport label> baseball input > type =radio label> football input> type ="radio label> football input>type=radio legend> whats you fav food etc.. ```
159
What is the difference between Legend and Label?
Legend is the name of a section of related inputs. Label is the name of the input themselves
160
How do you add a DatePicker to your page?
input type=date>
161
What is the Time tag and what does it do with the Datetime attribute?
The time tag is used with the datetime attribute to wrap a date in text. This is to standardize time that may be written informally and can be used by screen readers and others assistive devices. we went on
162
If an element is Screen Read Only, what does that mean?
It means that the element cannot be seen but the information is read by a screen reader.
163
Why would we want an element to be Screen Read Only?
If we have a chart that requires sight to get the information from it. You might have to also make a table for a screen reader to read the table the make the information accessible. But you dont want to put a chart and a table, because it does no good to have both. So you would show the chart for those that can see and make the table screen read only so it is read to those who cant see the chart
164
What is the syntax for making something Screen Read Only?
``` .sr-only { position: absolute; left: -10000px; width: 1px; height: 1px; top: auto; overflow: hidden; } ```
165
If you make the CSS of an element Display: None or Width/Height: 0px?
No, these will make it so the screen reader ignores it too and it wont get read.
166
What is an Accesskey attribute and what is it used for? What is the syntax?
It is added to links on a page to allow keyboard users to click a key like SHIFT or CTL plus whatever value you add to the accesskey attribute and it will go to that page. a href ="wwf.com" accesskey="g" >
167
What two things does setting the attribute/value pair Tabindex="0" do to an element?
It makes it so it can tab to access it the same way you can links and buttons for key board only users and it can make it so that you can style it using the pseudo class :focus on it.
168
What does applying an integer high than 0 to the value of Tabindex do?
It makes sets the focus order for tabbed elements. The element with the value of 1 will go first and then 2 and then so on and so forth
169
What could be a unintended consequence of setting the values for Tabindex on elements?
Most if not all keyboard users are used to the keyboard focus on the hitting tab to go from top to bottom. When you set the tabindex it takes it out of normal rotation that could be confusing for some users
170
How do you change the visual appearance of something depending on the screen height and width?
You use a media query ``` @media (min/max-height/width: numpx) { element { property: value } } ```
171
How do we make images responsive in CSS? And what does the image need to be wrapped in?
it needs to be wrapped in a div or some sort of parent element ``` img { width: 100%; display: block; height: auto; } ``` The max-width of 100% makes sure the image is never wider than the container it is in. The height of auto will make the image keep its original aspect ratio
172
What trick do you do to pictures to make sure that they work well with Retina/IOS?
Make sure that you set the height and the width of an image to half of that of the original picture
173
Besides percentages and pixels what is another useful way to size objects or pictures based on the viewport itself?
Viewport units.
174
What does VW and VH stand for as measurement units?
Viewport Width and Viewport Height The number that goes with it is the percentage of that header { height: 100vh } means the header is going to be 100 percent of the viewports height.
175
What does Vmin and Vmax stand for as measurement units?
Vmin - of whichever screen is smaller | Vmax - of whichever screen is larger
176
Where can we use Viewport Units?
We can use them wherever we use px or %'s
177
What can you do to safeguard against browsers that dont support viewport?
you can set up, a regular declaration with px's directly before a Viewport Unit declaration and if the browser supports Viewport Units - it will use that instead. If it doesnt it will use the regular px declaration
178
What happens when you add Display: flex to a container that has block elements nested inside of it?
They become stacked horizontally left to right
179
What is a Flex Container?
It is a parent element that has display: flex applied to it
180
What is a Flex Item?
A child of a flex container that will move depending on how the flex is applied
181
What is Flex-Direction?
This is the property that dictates the direction that the flex items are displayed in
182
What is the default Flex-Direction?
Row
183
What are the Four Flex Directions?
Row, Row-Reverse | Column, Column-Reverse
184
What is the Main Axis of a row?
horizontal line going right through it
185
What is the Main Axis of a column?
vertical line going right through it
186
What is Justify-Content Css property?
This property aligns flex items along the main axis of the flex direction.
187
What does Justify-Content: center; do?
It places the flex items along the main axis in the center of container.
188
What does Justify-Content: flex-start do?
It places the flex items on the main axis along the beginning of the container.
189
What does Justify-Content: flex-end do?
It places the flex items on the main axis along the end of the container.
190
What does Justify-Content: space-between do?
Places outer most flex items along the border of the flex container and divides the spaces in between the remaining flex items
191
What does Justify-Content: space-around do?
Splits between the items looks double what they are along the edges because each item gets its on space buffer - which between them looks like double space.
192
What does Justify-Content: space-evenly do?
It makes the space between the flex items even on both sides regardless of the amount of space or items
193
What is the Cross Axis of a Row?
The vertical line.
194
What is the Cross Axis of a Column?
The horizontal line.
195
What does the property Align-Items do?
It alings flex items along the cross axis of a flex container
196
What does Align-Items: flex-start do?
It aligns the flex items along the start of the cross axis
197
What does Align-Items: flex-end do?
It aligns the flex items along the end of the cross axis
198
What does Align-Items: center do?
It aligns the flex items in the center of the cross axis
199
What does Align-Items: stretch do?
It stretches the flex items the full height/width of the flex container depending on the cross axis of the flex direction
200
What does Align-Items: baseline do?
It will make sure that the text inside of the flex elements are lined up even if the actual height/width are not exactly the same amongst the flex items. This helps your texts look consistent
201
What does Flex-Wrap do?
It tells CSS to wrap flex items to the next row or column if there isnt enough space on one line.
202
What determines if there is enough space to wrap flex items?
The space of the container and the space of the flex items.
203
What is the default value for Align-Items for grid items?
Stretch.
204
What is Flex-Wrap: No Wrap?
This setting does not wrap flex items and keeps all flex items on the same line.
205
What is the default setting of Flex-Wrap?
no-wrap
206
What does Flex-Wrap: Wrap do?
It wraps flex items on to the next line depending on the flex direction of the container
207
What does Flex-Wrap: Wrap-Reverse do?
Wraps items in the opposite order of Wrap
208
What does Flex-Shrink do? When do we use it?
When the flex container's width/height is smaller than the combined width/height of the flex items, Flex shrink can be used on flex items to allocate which items will shrink faster or slower than other items. The higher the number, the higher the shrink rate. flex-shrink: 3 will shrink three times as fast as flex-shrink: 1
209
How can Flex-Shrink be used with Width/Height?
When flex items are in the same container as long as the container is big enough to have both items have their width/height measurements respected, both will fine. Once the flex container gets smaller and encroaches on the size of the flex items, the flex items will shrink at the desired rate you set on the Flex-Shrink property. #box1 { width/height: 200px; flex-shrink: 2 } #box2 { width/height: 200px; flex-shrink: 1 } if the flex container is at 600px, both of these boxes will be 200px each, because there is enough space to accommodate both widths/heights. But if that container were to go down to 300px. Then Flex-shrink would come into play and shrink box 1 and twice the rate as box #2 meaning the 300px would leave the boxes as box 1 100px box 2 200px
210
What happens if you add 100% width/height on all the flex items?
They will divide it up evenly and give each other equal parts.
211
What happens if you add Flex-Shrink on to flex items with 100 percent width/height on each of them?
If there is two and given different flex shrink values then they will automatically adjust to divide up the space. If two or more or given and are given different values, more often than not only two elements will be divided up and the other elements will be shrunk to the point where you dont see them
212
What is the default value for Flex-Shrink?
1
213
What is Flex-Grow? How does it work?
It works exactly the same as Flex-Shrink except when the container expands it grows the flex items at the rate that you decide
214
How do you set the starting point of a flex item before it starts growing or shrinking?
flex-basis : with some measurement value
215
Why is it a better idea to use Flex-basis as for flex items rather than width/height or min-width?
Because you can do it in the short hand notation of Flex. And when it comes to min-width, when you get to that small size say for a photo, the image will stay the same size but just make you scroll to see it. where flex basis will actually shrink the photo or the element to fit into thay space rather than make you scroll.
216
What is the syntax for the shorthand Flex property?
flex : grow, shrink, basis
217
What is the Order property?
It puts the flex items in the order that they should appear. The number value is that order, it can take negative nums too order: 1 order: 2
218
Whats the default of the Order property?
Flex items will be ordered in the order that they appear in the source HTML
219
What is the Align-Self property?
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.
220
What values does Align-Self take?
align-self accepts the same values as align-items and will override any value set by the align-items property.
221
Can any HTML element be made into a Grid Container?
Yes any HTML element
222
How do you turn an HTML element into a Grid Container?
You apply display: grid; to it This gives you the ability to use all the other properties associated with CSS Grid
223
How do we add Grid Columns to a Grid Container?
We use the property grid-template-columns
224
How are the number of columns determined by Grid-Template-Columns?
The number of values applied to the property determines the amount of columns the container will have. grid-template-columns: 50px 50px 50px 50px This container would have 4 columns
225
How is the width of columns decided when creating columns with Grid-Template-Columns?
The measurements of the values determine the width of the columns grid-template-columns: 50px 50px 50px 50px This will set 4 columns of 50px in width each.
226
How do you make Rows instead of Columns with CSS Grid? How does it work?
grid-template-rows it works the same way as grid-template-colums
227
What measurements can we use for Grid-Template-Columns/Rows? And how do they work?
We can use the usual set units like px/vh/vw We can use percentages We can use auto (which size is only that of the content it has, like a inline element) We can use Fr (this works like a fraction, the number represents the parts it will take up of the remaining space) grid-template-rows: 1fr 2fr This will divide the container into three parts.... the first row will get 1/3 and the second row will get 2/3
228
How do you create a gap between Columns when using Grid-Template-Columns?
grid-column-gap
229
How to specify how big of a gap is made when using Grid-Column-Gap?
The value will determine the size of the gap in between the columns
230
How do we create gaps between rows when using CSS Grid? How does it work?
gird-row-gap it works the same way as grid-column-gap
231
What is Grid-Gap? And how is it used?
Its a shorthand for column/row-gap properties. If it has one value, it will set the width for all columns and all gaps if it has two values, the first one is for rows and the second one is for columns
232
Grid-Column/Row are not used on Grid Containers, what are they used on?
They are used on Grid-Items.
233
What are Row and Column Lines?
Think of a Grid....the lines that go horizontal are the row lines. the lines that go vertical are column lines. The number of column and rows determine the amount of lines there are. These lines are numbered from the top left corner of the page and run downwards for columns and to the right for rows 1 2 3 4 2 3 4 a four column/row grid would look like this
234
How does Grid-Column/Row work?
You give two numbers on the value of grid-column/row the first number is the line that you want the grid item to start then a forward slash the second number which is the line that you want the flex item to stop. so grid-column: 2/4 would start on line 2 go across line 3 and stop on line 4. Meaning this item would cover two columns
235
What is the Repeat value on the Grid-Template-Row/Column property? What is the syntax?
The repeat value will allow you to make as many columns or rows of a particular container that you want. It takes two parameters. The first one is how many rows/columns that you want. The second will be the width/height grid-template-columns: repeat(3, 1fr) This will make 3 columns that take up 1/3 of the container each.
236
What is a Cell in CSS Grid? Is every Cell a Flex-Item?
It is the space in which the Flex Item sits. The space in between the row/column lines that make up the columns/ rows. Every Cell isn't a Flex-Item. They would occupy the same space but Cells can be empty. Think of Cell as Jail Cell, but Flex Items are the prisoners inside of the cell. They can move around the cell and be in different positions of the cell, the cell could be empty - but the prisoner and the cell are not the same even if they occupy the same space.
237
How can you move the content HORIZONTALLY inside of a CSS Cell?
You can use the property justify-self
238
What is the default value of the Justify-Self property in CSS Grid? What does it do?
Stretch. This will make the content fit the entire width of the cell.
239
What are the values of Justify-Self property in CSS Grid?
Start - justifies the item to the left of the cell. Center - justifies content to the center of the cell End - justifies content to the end of the cell Stretch - content covers entire width of the cell
240
How do you can you move content Vertically inside of a CSS Cell? And what values does it take?
By using the align-self property. It takes all the same values as justify-self
241
If you want to move the content inside of the Cell Horizontally for all the Grid Items what can you use? What values does it take?
justify-items Takes the same values as justify/align-self:
242
If you want to move the content inside of the Cell Vertically for all the Grid Items what can you use? What values does it take?
align-items Takes the same values as justify/align-self
243
What element do you apply Align/Justify - Items on when making a grid?
the Grid Container
244
When you use Justify/Align-Items on content, How will the height and width be determined?
The height and the width will be determined by what the content dictates.
245
What is an Area in CSS Grid? How do they work?
An Area are rows of the container grouped together by a custom/variable/class name Each row is placed between quotations 1 2 3 4 1 "header header header header" 2 "ad content content ad" 3 "content content content content" 4 "footer footer footer footer" Each different name is a different Area
246
What if there is a section of your Grid that has empty cells, how would you label it when creating Areas?
You place a period where there is an empty cell.
247
How do you create Areas in CSS Grids?
use grid-template-areas: and then use quotations and to section off rows and classify custom cell names grid-template-areas: "header header header" "ad content ad" "footer footer footer" this will create 4 areas header, ad , content and footer
248
Does creating Grid Areas, does that automatically place the Grid-Item into it? Meaning, are they linked for CSS styles and things of that nature?
No, creating the area is literally assigning a name to the space, Not to the Grid item itself. The Grid Item will still need to be linked to the area name.
249
How do you assign an Grid Item to a Grid Area?
By using grid-area on the grid item item1 { grid-area: header, } This lets the grid know that you want the item1 class to go in the area named header. In this case, the item will use the entire top row because that whole row is named as the header area.
250
What is you want to add an Area to an item in particular to a grid that doesn't have a Grid-Template-Row/Column property set?
you can use grid-area the values are separated with forward slices the values are horizontal start / vertical start / horizontal end/ vertical end grid-area: 1/1/2/4; So the item in the example will consume the rows between lines 1 and 2, and the columns between lines 1 and 4.
251
What if you wanted to make multiple Rows/Columns with the same width, but wanted to make one or more with different width/height than the rest?
You can add another value after/ before the Repeat( ) function. grid-template-columns : repeat(3, 50px) 100px; this would make 3 columns that are 50px each and then put a column that is 100px after it.
252
How do we use the Minmax function along with Grid-Template-Row/Column? Whats the syntax?
This is used to set the min and the max width/height of the row/column after setting the starting width/height in the event that the container/browser grows/shrinks. minmax( min , max) grid-template-rows: repeat(3,50px) minmax( 25px, 100px) this will make three rows where the height is set to 50px, but when the container shrinks it will shrink the rows up until it reaches 25px if the container grows the grid items will grow until it reaches 100px
253
Can you use the Minmax function inside of the Repeat function?
Yes you can. grid-template-columns: repeat(3, minmax(90px, 1fr)) ; This will make a three columns that will take up 1/3 of the container but will not get smaller than 90px
254
How do you use Auto-Fill with the Repeat function? What does it do and what is the syntax?
Auto fill allows the container to add rows/columns when the container grows or shrinks. If there is Grid Items they will slide up to fill the row/column if the container grows, if it shrinks the Grid items will wrap to the next column/row repeat( auto-fill , minmax(90px, 1fr) this will look at the container size and see how many 90px's can fit into the height/width and make the proper amount of rows/columns. The item will never go less than 90px. As the screen grows, each item will take a fraction of the total amount of rows/columns. So if they are 5 columns - the grid items will take 1/5th - if there 10 rows/columns the grid items will 1/10th of the container.
255
What is Auto-Fit and how is it different than Auto-Fill?
auto-fit works almost identically to auto-fill. The only difference is that when the container's size exceeds the size of all the items combined, auto-fill keeps inserting empty rows or columns and pushes your items to the side, while auto-fit collapses those empty rows or columns and stretches your items to fit the size of the container. Note: If your container can't fit all your items on one row, it will move them down to a new one. auto-fill: 1 2 3 4 5 6 empty empty empty empty auto-fit: 1 2 3 4 5 6
256
How can we use Media Queries with Grid-Template-Areas to make our pages responsive?
When can name our grid areas and then change them depending on the grid size set: ``` grid-template-areas : "header" "advert" "content" "footer"; ``` this is one column; 4 rows - at 300px we can change that when we get to 400px ``` @media query (min-width: 400px) { grid-template-areas: "advert header" "advert content" "advert footer"; ``` This will make 2 colums; 3 rows and take the advertisement section and place it along the left side of the page.
257
Can you make a Grid inside of a Grid?
Yes, take one of the Grid Items, and in the CSS apply display: grid; and grid-template-row/column: and define the grid that you want.
258
What is the most efficient way to get unstuck when you are stuck on a coding problem?
When you get stuck, remember: Read-Search-Ask. Read the documentation or error Search Google Ask your friends for help
259
How do we link a CSS file to a HTML file?
link rel="stylesheet" type="text/css" href="tribute.css" />
260
Whats the best way to add images to Grid's?
use the background image property on the grid item and then place : background-size: cover; background-position: center; background-repeat: no-repeat; on the grid container
261
What is the CODE tag used for?
It turns the text inside of into monospace. This code is where you add code to the page. This code tag is semantic.
262
Should you comment out regularly and explain what your code is doing?
Yes, this is a good practice for others that need to see your code and know what it is doing, But also to your future self to help explain what your code is doing as sometimes it gets confusing.
263
In computer science what does DATA refer to?
anything that is meaningful to the computer
264
JavaScript provides eight different data types which are?
undefined, null, boolean, string, symbol, bigint, number, and object
265
What is the term we use for creating a variable?
Declaring a variable.
266
What are variables ?
They are nicknames for a particular piece of Data
267
Are the Variables the same as the Data they are assigned to?
No Variables are just a label that POINT TO the data, but are not the data itself.
268
Can Variables store different Data at different times?
Yes they can. They can be dynamically changed
269
What is the Assignment Operator?
the equal sign =
270
When assigning a Variable does assignment go from left to right, or right to left?
Assignment goes from right to left, meaning everything on the right of the equal sign is resolved before the value is assigned to the variable on the left
271
What is Initialization?
Initialization is giving a declared variable its first value
272
What are the two steps of assigning a Variable and giving it a value?
Declaration and Initialization var myName (declaration) = rashaan (initialization) var myName = rashaan declaration and initialization
273
If you declare a variable but do not initialize it, what value does it have?
undefined.
274
If you do a mathematical operation on an undefined variable what will the result be?
NaN,
275
What does NaN stand for?
Not a Number.
276
If you Concatenate a string with an undefined variable what will the result be?
string of Undefined
277
How can increase and decrease a variable with a number data type by one
withe the ++/--operator variableName++ (+ 1) variableName-- ( - 1)
278
What is a Float Number?
a decimal number
279
What do we need to remember about the accuracy of Floating numbers?
Not all real numbers can be represented in Floating Numbers, this can lead to rounding errors.
280
Can you use the same Mathematical Operators on Float numbers as you would Integer numbers?
Yes you can.
281
What are Integer numbers?
Whole numbers
282
What is the Remainder Operator?
% and it gives the remainder of the division of two numbers.
283
How can we use the Remainder Operator to check if a number is even or odd?
We can use the operator by two... and if it has a remainder it is odd and if it doesnt it is even. myVar % 2 = 1 (odd) myVar % 2 = 0 (even)
284
What should we not confuse the Remainder Operator with?
The modulus operator. It is very similar but does not work properly with negative numbers.
285
What is Compound Assignment?
When you want to update the current variable with a new value using a mathmatical operator. myVar =+ 5 this is the same as myVar = myVar + 5
286
When using Compound Assignment which operator comes first?
The Math Operator comes first and then the Assignment Operator += -=
287
What is a String Literal?
A series of zero or more characters that are enclosed in single or double qoutes.
288
What is Escaping Quotation marks with a BackSlash?
Every string needs to start and end with single or double quotes. But when we need to use quotes inside of a string, we can use a BACKSLASH \
289
Where do we place the Escaping Backslash in relation to the inside Quotes?
Before both sets of Inside Quotes. \" lets go \"
290
How do you Escape Quotation marks with other Quotation marks?
Every string needs to begin with matching sets of single or double qoutes. If you start with single you can safely use doubles inside of the string, and vice versa
291
How do we Escape a Backslash to show a Backslash inside of a string?
\\
292
What does \n mean inside of a string?
it creates a new line in the string
293
What does \t mean inside a string?
it means Tab and creates a tab sized space inside a string
294
What is the Concatenate Operator? What does it do?
It is + It is used with strings and creates new strings by adding them together
295
When using the Concatenate Operator does it add spaces?
No it doesnt, so you have to add the spaces yourself.
296
How do we use Compound Concatenation?
We can add a string to the end of another string var ourStr = "I come first. "; ourStr += "I come second."; ourStr is now "I come first. I come second."
297
Can you Concatenate strings with Variable Names?
Yes, you dont need to use quotations with variable names. ``` var ourName = "freeCodeCamp"; var ourStr = "Hello, our name is " + ourName + ", how are you?"; // ourStr is now "Hello, our name is freeCodeCamp, how are you?" ```
298
How to Concatenate Variable Names with other Variable Names?
We can use Compound Concatenation ``` var anAdjective = "awesome!"; var ourStr = "freeCodeCamp is "; ourStr += anAdjective; // ourStr is now "freeCodeCamp is awesome!" ```
299
What is a String Variable as opposed to a string literal?
It is a variable name that has a string stored inside of it myStr = "this is a string" myStr (string variable) "this is a string" ( string literal)
300
How can you find the length of a string from a String Literal and a String Variable?
by using .length on the end of it. It will tell you how many characters are in the string. Even the spaces.
301
What is Bracket Notation on a string? What is the syntax?
It is a way to get a character at a specific index within a string? firstName = "Charles"; firstName[0]; firstLetter is "C"
302
What is Zero-Based-Indexing?
That the count on indexing doesnt start at 1 like normal. It starts with 0.
303
What does it mean if something are Immutable?
That it cannot be changed once it is set.
304
Are String Values Immutable? In Other words, Can you the individual characters in a String Literal be changed using Bracket Notation?
Yes they are. You cannot change the individual character of a string literal using Bracket Notation.
305
If String Variable values are immutable, how can we change the value?
We have to reassign the variable name to a different value all together. ``` var myStr = "Bob"; myStr = "Job"; ```
306
What does the nth number mean?
Its a generic number holder for an unknown number. its like the x variable in algebra
307
How do we use Bracket Notation to find the last character in a string?
variableName[variableName.length - 1] ``` var firstName = "Charles"; var lastLetter = firstName[firstName.length - 1]; // lastLetter is "s" ```
308
How do we Use Bracket Notation to Find the Nth-to-Last Character in a String?
You can add any number after the subraction operator to get that index character. firstName[firstName.length - 3]
309
Does Zero-Based-Indexing work the same way in reverse? For example, when using the [.length - n ] method to access characters at the end of a string?
No, zero based indexing only works in a linear fashion. the first character will be 0 no matter what and doesnt change depending on the way that you are counting.
310
How do we store several pieces of data in one place?
With an Array
311
Whats the difference between Using Bracket Notation on arrays vs Strings?
In arrays, the whole item is returned and not just the character
312
Are array entries/items Immutable?
No they are not, meaning you can change them using bracket notation. ``` var ourArray = [50,40,30]; ourArray[0] = 15; // equals [15,40,30] ```
313
What is a Nested Array?
It is an Array inside of another Array.
314
What is a Multi-Dimensional Array?
It is an Array of Arrays
315
How do we Index Nested Arrays and Multi-Dimensional Arrays?
We start indexing from the outside first and then work our way down ``` var arr = [ [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 ```
316
What does .push( ) do?
It adds the item or array inside the parens to the end of the array. ``` var arr1 = [1,2,3]; arr1.push(4); // arr1 is now [1,2,3,4] ``` ``` var arr2 = ["Stimpson", "J", "cat"]; arr2.push(["happy", "joy"]); // arr2 now equals ["Stimpson", "J", "cat", ["happy", "joy"]] ```
317
What does .pop( ) do?
This is used to take the value off the end of an array.
318
What does push( ) return?
The length of the new array
319
What does .pop( ) return?
It returns the item that was popped off the end
320
How can we store a popped off item of an array?
Store it in a variable storedVariable = array.pop( )
321
What does .shift( ) do?
Removes the first item of an array and returns it
322
What does unshift( ) do?
Adds an item to the beginning of an array and returns the length of the new array
323
What is a function?
It is a piece of reusable code.
324
What are Parameters?
Parameters are variables that act as placeholders for the values that are to be input to a function at the time that it is called.
325
What does are Arguments?
Arguments are the actual values that go in the place of parameters when the function is called.
326
What does "Passing through" an argument mean?
It means inputting the Argument values in the place of parameters
327
When we discuss Scope, what does it refer to?
The visibility of variables.
328
Variables that are defined outside of a function have what Scope?
They have Global Scope. Meaning they can be seen everywhere in your JS code.
329
Variables that are defined without using the keyword var/let/const are in what Scope?
They are in Global Scope.
330
Should you ever declare a function without using a Keyword like let/var/const?
No you should not. If you want to make it Global, then use a Keyword and Variable Name outside a function. If you want it local then declare it inside of a function
331
Why should you not declare a variable without using a keyword?
Because it will cause unintended consequences elsewhere in your code and it will be really hard to debug
332
Variables declared within a function have what Scope?
They have local scope.
333
Variables that are passed through as Arguments have what Scope?
They have local scope
334
What does Local Scope mean?
It means that the variable can only be seen within that specific function
335
When there is a Global and Local Variable with the same name which one takes precedence?
The Local Variable takes precedence over the Global.
336
When do we use a Return Statement in a function?
When we want to send a value outside of the function
337
What happens when your function produces a value but does not have a return statement?
It produces an Undefined result.
338
What two values do Booleans have?
True or False
339
Are Boolean Values every written in Quotations?
No they are not.
340
What are If Statements?
They are code that allows you to run one type of code if the boolean is true and another type of code if the boolean is false
341
What are Comparison Operators?
These are operators that compare two values. like lesser than and greater than >
342
What values do Comparison Operators return?
Booleans (true or false)
343
What is the Equality Operator?
== This checks to see if the left value is equal to the right value. If so True is returned if not False is returned
344
What is Data Type Coercion? When is it used?
It is when the Equality Operator is used on two different data types... this converts the data into the same type and then compares them. 1 == 1 // true 1 == 2 // false 1 == '1' // true "3" == 3 // true the strings and the number data types return true because their value is equal even though the data type is not
345
What is the Strict Equality Operator? How does it work?
=== It works the same way as the Equality Operator except that it doesnt perform Data Type Coercion. Meaning the data type and the value have to be equal for it to return a true. 3 === 3 // true 3 === '3' // false
346
How can you check the type of data something is?
by using the typeof operator. typeof 3 // returns 'number' typeof '3' // returns 'string'
347
What is the Inequality Operator? How does it work?
!= It works the same way the Equality operator does except it returns True when unequal and False when they are equal. This perfroms Data Coercion
348
What is the Strict Inequality Operator?
!== It works the same way as === except it returns True when they are unequal and False when they are equal
349
Does Type Coercion also take place with > Greater than or < Less than or >= or <=?
Yes, these will compare different data types
350
What is the && Operator?
It returns true if both sides of the operator are true. Otherwise it returns false.
351
What is the | | operator?
It returns True if at least one side of the operator is true
352
What should we keep in mind when we are creating If/Else statements about the order that we put them in?
The If statement will stop executing at its first true. So Its important to put it in the right order. ``` This is the wrong way: if (val < 10) { return "Less than 10"; } else if (val < 5) { return "Less than 5"; } else { return "Greater than or equal to 10"; } } ``` If the whats passed in for Val is a 2.. it will return a true and stop running the code. Its less than 10, but its more correct to say that its less than 5. Thats the code we want to run. ______________________ ``` This is the right way if (val < 5) { return "Less than 5"; } else if (val < 10) { return "Less than 10"; } else { return "Greater than or equal to 10"; } } ``` If 5 returns a false, then we look to see if its less than 10 and so on and so forth.
353
What is a Switch Statement?
It does the same thing as If statement but can run code if there are more options than just True or False. We can use this when there are more options available than just the two
354
Can a Switch Statement be used in another function?
Yes, its just like an If statement, it can be used inside of a function.
355
Do we need a parameter when starting a switch statement ?
Yes we do, we need to pass in an argument to a parameter
356
How do we begin a Switch Statement?
switch (param1){ }
357
What is a Case when using a Switch Statement? What is the syntax?
A Case is a possible value for the Param. There can be as many as you want. case "value" :
358
How does the Beginning of a Switch Statement look with one case option?
switch (param){ | case "value" :
359
Where do you put the code that you want ran when the Argument matches a Case?
You place it after the colon after the case value. case "value" : console.log('this code')
360
What does a Switch Statement look like with its beginning, case statement and code to be ran?
switch (param){ case "value": console.log('run this code')
361
What is a Break Statement inside of a Switch Statement?
It Breaks the code from executing the rest of the switch function and allows the code to move down the document.
362
If there is no Break in the switch statement, what happens?
If theres no break, then the code will keep executing even if the param found its matching case
363
What is a reason that you might purposefully leave out a Break in a switch Statement?
If you have multiple possibilities for the param but would like them all to run the same code as a result. ``` switch(animal) case 'cow': case 'pig': case 'duck': console.log('This is a farm animal') break case 'spider': console.log('this is not a farm animal) ``` There is no break for the first three options, meaning if the animal value is one of those three it will return the same code and then break. but if it takes spider, then it will return a different code.
364
What is a Default Statement in a Switch Statement? What is the syntax?
This is like an Else in an If Statement. If the parameter doesn't get passed a value that matches one of the Cases...it will run whatever code is in the default section. default :
365
How would a 3 Case Switch Statement look with Breaks and a Default?
``` switch(team){ case "49ers": console.log('49ers') break; case "Giants": console.log('Giants') break; case "Warriors": console.log('Warriors') default: console.log('if it aint these, then it aint shit) } ```
366
Are Case values in Switch Statements tested against Normal Equality or against Strict Equality?
Strict Equality.
367
What happens when a Return Statement is reached inside of a function?
The execution of the current function stops. ``` function myFun() { console.log("Hello"); return "World"; console.log("byebye") } ``` The above outputs "Hello" to the console, returns "World", but "byebye" is never output, because the function exits at the return statement.
368
Whats the difference in the way Objects are indexed/accessed as opposed to Arrays?
Arrays items are indexed/accessed by Numbers representing their location within the array Objects are indexed/accessed by their properties
369
What are two ways to access the properties of an object?
Dot Notation and Bracket Notation.
370
When must you use Bracket Notation on an Object?
If the property of the object you are trying to access has a space in its name, you will need to use bracket notation. ``` myObj = { "Space Name": "Kirk", "More Space": "Spock", "NoSpace": "USS Enterprise" }; myObj["Space Name"]; // Kirk myObj['More Space']; // Spock myObj["NoSpace"]; // USS Enterprise ```
371
Property Names of an Object that have spaces in them must be put inside of what?
property names with spaces in them must be in quotes (single or double).
372
How can you use Bracket Notation to to access Object Properties using Variables?
You can store a key name of an objects key/value pair inside a variable and use Bracket Notation on that variable name to access the information in the object eventhough that variable name isnt in the object itself. example ``` obj = { 8: Farve, 16: Montana, 12: Marino } ``` We can save the number 16 to a variable name. playerNumber = 16 then we can use the new variable name in object bracket notation even though the variable name isnt in the object itself obj[playerNumber] This would return Montana, just as it would if you ran obj[16}
373
How can we update a Object's Key/Value pair?
With Bracket or Dot Notation. we update this object's name property: ourDog.name = "Happy Camper"; or ourDog["name"] = "Happy Camper"
374
How can we add key value pairs to an Object?
We can use Dot or Bracket Notation. The same way we would modify an existing key/value pair we can add other and new key value pairs
375
How do we delete key/value pairs in an object?
By using the delete keyword. delete objectName.propertyName
376
How can we check to see if a Object has a particular property 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 myObj.hasOwnProperty("top"); // true myObj.hasOwnProperty("middle"); // false
377
What is a While Loop? Whats the syntax?
Its a loop that runs WHILE a specific condition is true. ``` var ourArray = []; var i = 0; while(i < 5) { ourArray.push(i); i++; } ``` this will produce an array with the numbers going from 1 - 5
378
When using a loop and you want to increment or decrement by more than one, we cant use ++ or --. So how can we so this?
We have to use Compound Assignemnt i += 10 this will iterate it by 10 every iteration instead of i++ and you cant just say i = 10
379
Can you nest For Loops inside of other For Loops?
Yes you can. The outer loop will begin the inner loop and when the inner loop stops the outer loop will loop the inner loop again until both loops are completed.
380
What do we need to remember when we are looping through Nested Arrays/Multi-Dimensional Array's?
We have to remember that we have to add the outer loops variable to the second loop. For example, first loop will take something like array.length; i++ to dictate when it stops and how it increments the inner loop will have something like, array[i].length; i++; because we need i to access the inner arrays inside of the outer array
381
What is a Do...While Loop?
It is the same as a While Loop except that it runs a piece of code once before it starts the looping. Do...this then Loop that. Normal While Loop ``` var ourArray = []; var i = 5; while (i < 5) { ourArray.push(i); i++; } ``` This fails because i = 5 so it wont loop when its time to loop so ourArray will be empty. Do..While Loop ``` var ourArray = []; var i = 5; do { ourArray.push(i); i++; } while (i < 5); ``` This also has i = 5 but the code following Do will run first and then the loop will start. but i = 6 after the Do code so the while loop wont execute so we will have ourArray = [5]
382
What is the Syntax for a Do....While Loop? What happens with the code that happens in the do block? What happens to the code in the while loop if one is written?
do { (code you want ran once regardless of condition. This code will keep running as long as the condition is true) i++ (or however you want it to loop) } while ( will run as long as this is true){ (this code if written will run once when the loop comes to an end) }
383
What is Recursion? What does it refer to?
Recursion refers to a function calling itself inside of it. Basically the name of the function where its declared and created is also in the return function of that function ``` function MULTIPLY( ) { if ( some condition) { do some code } else { return MULTIPLY( ) } ```
384
Recursion can be used in place of what?
Loops.
385
What is a Base Case when in reference to Recursion?
It's the part of the code that that stops the calling of the function when a certain criteria is true or met. Basically the STOP CODE.
386
What is the Recursive Case in reference to Recursion?
Its the part of the code that dictates how the function will call itself. It will have some sort of modification so the output will be different each time it is called until it reaches the base case
387
What is an Example of a Recursive Function that adds together elements of an array by their index ?
The goal is to add elements of an array together using their indexes. var times = [1,2,3,4,5] ---- example Array sum(arr , n) --- name of function and params representing array, and stopping place for the function to stop calling itself. if (n <= 0 ){ --- This is where we set our BaseCase, and tell the code when to stop. It doesnt have to be zero. If you want specific of an array.....say starting with the third item in an array, you can adjust the number 0 to handle that. Zero here is an arbitrary number. This might work well for a countdown app, where you want the function to call itself until it reaches the first item in an array or the number 0 itself. But it doesnt have to be a zero return 0 --- This is what we want to happen instead the function being called again. Again, can be anything. But in the case of a countdown, you might want it to return zero as the final number in the countdown. Or can say something like "Happy New Year" ``` else { return sum(arr, n - 1) + arr[n - 1] } ``` This is the the recursive case where we call the function again. What this is doing in the first N is controlling how many more times the function will run the second N gets the value from the array by its index. so everytime it runs it logs the value of the array index so if N = 5 it would add the array index 5 plus 4 plus 3 plus 2 and keep going this way until N reached whatever value was set in the IF statement Example of full code: ``` function sum(arr, n) { if ( n <= 0){ return 0 } else { return sum(arr, n - 1) + arr[n - 1] } } ```
388
Must you use Bracket Notation when accessing object properties with a function Parameter/Argument?
Yes you must use bracket notation otherwise it will come up as undefined and youll want keep doing it over and over and want to shoot everyone in the face
389
What does Math.random( ) do?
It creates a random decimal number. It can make any decimal number including 0 - 1... it can return 0 but it will never return 1
390
How do we generate a Random Whole Number? And what do we need to remember about how it rounds down?
Math.floor(Math.random() * whole number) this will create a random whole number below the whole number. It rounds down to the nearest whole number, so if you put Math.floor(Math.random() * 20) it will choose a random number between 1 -19 but it will never choose 20, so you have to account for that in your code
391
How to create a Random Number within a range of numbers?
Math.floor(Math.random() * (max - min + 1)) + min console.log(Math.floor(Math.random() * (20 - 10 + 1 )) + 10) will only produce numbers between 10 - 20
392
What does parseInt( ) do? What does it return when used with a number and when its used with something that cant be converted into a number?
It turns a string into an integer... so a = parseInt("007") would make a = 7 if you try to use parseInt and the first character of the string cant be made into a number it will return NaN
393
When is an example of a time where you might need to use parseInt and turn a string into a number?
Some times in your JSON and API calls you get strings that are numbers and this is a good way to turn them into numbers.
394
What is a Ternary Operator? What is the syntax?
It is a one line if/else statement. condition ? statement if true : statement if false
395
Can you chain multiple Ternary Operators together? What is the best practice?
Yes you can and the best practice is to start each additional ternary operator on another line. That way it is easy to read Each new lines begins with the colon
396
What happens if you dont put Return in the Base Case of a Recursive Function?
It will continue and eventually overflow
397
How does Recursive Functions affect the JS Call Stack?
The functions that are called in an recursive function, do not return anything at first, they are merely put inside of a queue and are waiting until the Base Case is reached. Once the base case is reached then, that return sets off a chain reaction that will start with the base case function (1 or 0 usually) then that will fire the next one and the next one and the next one.
398
How to create an Array inside of a Recursive Function?
Create an empty array or an array with starting values in the Base Case - and then assign the recalled function to variable name and then push or unshift from there in the recursive case ``` function recursiveFunctionName(arrayParam, numParam){ if ( numParam <= 0){ return; } else { arrayParam.push(numParam) console.log(arrayParam) return recursiveFunctionName(arrayParam, numParam - 1) } } ```
399
Why should you not use the Var keyword to declare a variable?
Because the original value declaration can be overwritten without throwing an error. So you can ruin your code bigtime and not even know
400
When you use Let as a variable it creates a local variable, but so does Var...Whats the difference in usage between these two in this case?
Let is tied and bound to not just the function but whatever expression it is tied to. So its possible to have a variable have a value in a loop statement and then a different value in an if statement in the same function. But this is not encouraged to do.
401
What is the difference between Let and Const?
Const is 'read only' meaning that it only can be read and its value cannot be changed once it is set.
402
What is a common practice of typing Const Variables to not confuse them with Lets?
Typing them in ALL CAPS and separating words with underscores.
403
Const Variables cannot have their values reassigned, can they be changed at all?
Yes, the can be updated and mutated. for example a object or an array can be updated with dot or bracket notation just like it would be if declared with LET ``` const s = [5, 6, 7]; s = [1, 2, 3]; // throws error, trying to assign a const s[2] = 45; // works just as it would with an array declared with var or let ```
404
What does Object.freeze( ) method do?
This makes an object unchangeable. Any attempt to update or delete the properties on a frozen object will be ignored and an error will not be thrown - it just will be ignored.
405
What is an Anonymous Function? What is a syntax example?
It is a function that doesn't have a name, and it doesn't have a name because it wont be reused. ``` function() { const myVar = "value"; return myVar; } ```
406
How can we write an Anonymous Function as an Arrow Function?
(Anon) ``` function() { const myVar = "value"; return myVar; } ``` ``` (Arrow) () => { const myVar = "value"; return myVar; } ```
407
What two things can we Omit from our Arrow Function when the function doesn't have a Function body and only a Return Statement?
Arrow functions can omit 1. Return Keyword 2. Curly Brackets This helps it be on one line and easier to read () => "value";
408
When an Arrow Function has only one Parameter what can be omitted from it?
The parenthesis that go around the parameter. item => item * 2;
409
How do we pass more than one Parameter in an Arrow Function?
We place them inside the parens like normal functions. (item, multi) => item * multi
410
What does the .concat( ) method do? What is the syntax?
str/array.concat(str/array) This adds a string to another string.
411
What is a Default Parameter and how is it used? Whats the syntax?
A Default Parameter is a parameter that you give a default value to in the event that one isn't specified. This can be used to set a parameter that you want something to be the majority of the time and change under specific circumstances. To do this you add = value to the parameter. ``` function (greeting = Hi , name = Rashaan) { ``` return greeting + name } Hi Rashaan this function can be called with other parameters for name or greeting and it will change. But if no other one is specified it will say Hi Rashaan as the default instead of throwing an undefined error
412
What is a Rest Parameter? What is the syntax?
A parameter is a parameter that is an array basically, it holds more than one value in its value name and can be accessed with various array methods like .reduce( ) .map( ) etc
413
What is a Rest Parameter? What is the syntax?
A parameter that accepts multiple unrelated values and puts them inside an array to be used and accessed within a function. for example calling restTest(2, apples, oranges, bananas) function restTest(param1, ...arr2) will treat Param 1 as the value 2 and put apples, oranges and bananas in an array that you can then use array methods on like reduce or map or filter etc
414
What is the Spread Operator and how is it used? Whats the syntax?
It looks the same as the Rest Parameter ...variableName. it takes an already made array and makes it able to used to 1. add new elements to arrays 2. pass elements of an array as parameters of a function 3. copy arrays 4. concatenate arrays
415
How do you use the Spread Operator to Add Elements to an existing array?
just add the spread operator into the existing array or use an array method to add it an existing array and this will make one new array. No spread array fruit = [grapes, bananas] {apple, orange] + fruit returns [apple, orange, [grapes, bananas ]] Spread Array fruit = [grapes, bananas] [apples, orange, ...fruit] returns [apples, oranges, grapes, bananas]
416
How to pass elements of an array as arguments to a function using the Spread Operator?
fruit = [grapes, bananas, oranges] ``` function (...fruit) { } ``` this allows you to use the array in the function
417
How do you copy an array using the Spread Operator?
You just store it in another variable name ``` arr1 = [1,2,4] arr2 = [...arr1] ``` arr2 = [1,2,4]
418
How do you use Spread Operator to concatenate Arrays?
Save two arrays to another variable name by making an array containing two spread operators. This will add both arrays into one big array accessible throught the new variable name. arrAll = [...arr1, ...arr2]
419
You can use the method concate( ) to add arrays together, why might you choose to use the Spread Operator over this method?
You might choose to use the Spread Operator if you want to add other elements along with the array. fruit = [oranges, bananas, apples] fruitALL = [grapes, kiwis, ...fruit, "pineapples"] This allows you to add not only the array under fruit but also add pineapples. Where using array.concate.(array) wouldnt allow you to do that. Also, you can decide where you want the array to take place using the Spread Operator fruit = [oranges, bananas, apples] fruitALL = [grapes, kiwis] you can add fruit to fruit all like [grapes, ...fruit, kiwis] and it will be [grapes, oranges, bananas, apples, kiwis] the array will go wherever you put it array.concate.(array) only allows you to put one whole array before another whole array
420
When using a Spread Operator is it possible to just use ...variableName anywhere?
No, this operator has to be used in place, meaning that it has to have some sort of Brackets or Parens around it such as array brackets or a parameter parens in a function ``` [...arr] function(...arr){ } ```
421
What is Math.max( ) and what does it do?
It takes numeric values separated by a comma and returns the largest value. Math.max (5,6,6,7, 734) returns 734
422
Can we use an array name with Math.max( ) ?
No you cant, it returns NaN you have to use the Spread Operator num = [32, 22, 112] Math.max(...num) returns 112
423
What is Destructuring Assignment and how is it used? Whats the syntax?
Destructuring Assignment is used to extract values from objects and apply them to variable names outside of the object. The names of the keys and the variable names will be the same { object key , object key } = object name ``` cat = { name: "whiskers" age : 14 color; "white" } ``` {name , color } = cat this will assign the value of cat.name to name and cat.color to color outside of the function
424
How do we assign Objects key Values to new Variable Names using Destructuring Assignment? Meaning, what do we do if we want to change the name of the variable so it doesn't match the key.
add colons and the new variable name after the object key name ``` cat = { name: "whiskers" age : 14 color; "white" } ``` {name : catName , color: catColor } = cat this will assign the value of cat.name to catName and cat.color to catColor outside of the object
425
Do you need to use a Keyword like Let or Const when using Destructuring Assignment?
Yes, you have to use a keyword otherwise it will throw an error
426
How do you use Destructuring Assignment for nested objects? What do we need to make sure we add along with the nested object key name?
You use it the same way as normal Destructing Assignment except you add more curly brackets around the objects. Everything else is the same. MAKE SURE YOU HAVE COLONS BEHIND THE NESTED OBJECT KEY NAME ``` const user = { johnDoe: { age: 34, email: 'johnDoe@freeCodeCamp.com' } }; ``` const { johnDoe: { age: userAge, email: userEmail }} = user; this will create a variable of userAge with the value of 34 and a variable of userEmail with the value of 'johnDoe@freeCodeCamp.com'
427
How do you use Destructuring Assignment with Arrays? What is the syntax
const [newName1, newName2, newName3 = [1, 2, 3] whatever is in the place of the 0 position will be assigned that and so on and so forth
428
How do we use commas in Destructuring Assignment with Arrays to skip places?
We add as many commas as needed and for every comma one item gets skipped. const [index1,,,,,,,,, index10] = [10,20,30,40,50,60,70,80,90,100] index1 = 10 index 10 = 100
429
How do we use the Rest Parameter with Arrays in Destructing Assignment?
We can use the Rest Parameter in conjunction to assign the remainder of an array to a variable name. const [index 1, index 2, ....restArrayName] = [5, 10, 15, 20, 45] ``` this will make index 1 = 5 index 2 = 10 and this will make restArrayName equal the rest of the array so [15,20,45] ```
430
How do we Use Destructuring Assignment to Pass an Object as a Function's Parameters?
In this case we want to just add the name of the keys that we want/ or the keys + new variable names we want to add to the values in the parameter place and then in the function block say what we want to do with it. ``` const stats = { max: 56.78, standard_deviation: 4.34, median: 34.54, mode: 23.87, min: -0.75, average: 35.85 }; ``` const half = ({max, min}) => (max + min) / 2.0; the values for max and min in the object is placed where the parameters go inside of curly brackets --t the curly brackets signifies the destructuring... then the arrow function to let us know were about to do stuff with it. and then in the function block we add both numbers and then divide the sum in half and save all of that to the half variable name.
431
What is a Template String?
its when you use backticks to add variable names or accessed data inside of a string it also can be used to make a string multi line let dataType = "string" ` this is a template ${dataType}` produces "this is a template string"
432
How can we use Object Shorthands to create new Objects? And when/how might we use them?
We can use Object Shorthands when we know that we are going to create multiple objects using the same keys For example, we are going to make and need objects of wrestlers that all are going to have the keys of name finisher title slogan instead of making each and every object, one by one every time -- we can make a function that will do it for us for example ``` const wrestler = (name, finisher, title, slogan) => { return { name, finisher, title, slogan } } ``` then we can just call the function with the values of the parameters and store it in a variable name and we wil have new objects const bretHart = wrestler("the hitman", "sharpshooter", "WWF", "Excellence of Execution") this will produce the object ``` bretHart = { name: the hitman, finisher: sharpshooter, title : wwf, slogan : excellence of execution } ``` and any time you need to make a function you just call it with the proper parameter values and it will create the object and then you can access it the way you would anything else bretHart.name returns "the hitman"
433
When calling functions inside of an Object what shorthand can we write to make it more concise?
So usually when we call a function in an object it will usually look like this : ``` const person = { name: "Taylor", sayHello: function() { return `Hello! My name is ${this.name}.`; } }; ``` We can take off the function keyword and we can remove the colon: ``` const person = { name: "Taylor", sayHello() { return `Hello! My name is ${this.name}.`; } }; ```
434
What is a Constructor Function? What is the job of such a function?
It is a function who's job is to construct/create an object
435
When making Constructor Functions should we use camel case?
No the first letter of every word should be capitalized
436
We can use Object Shorthands to create templates for new objects how can we use Constructor Functions to create the same type of template for Object creation? what is the syntax?
``` function ConstructorName(param1, param2, param3){ this.param1 = param1; this.param2= param2; this.param3= param3; } ``` const variableStore = new ConstructorName("value1", "value2", "value3") this will produce an object like this: ``` variableStore = { param1 = value1; param2= value2; param3= value3; } ```
437
How can you make a Constructor Function using the Class keyword?
``` class Wrestler { constructor(name,finisher,slogan){ this.name = name; this.finisher = finisher; this.slogan = slogan; } } ``` const bookerT = new Wrestler("Booker T", "Spinarooni", "Can you dig it?")
438
What 4 things do we need to remember about Constructor Functions?
1. You have to call them with the "new" keyword 2. You don't need a return statement 3. If you use Class you have to use the Constructor method/ if you use Function you dont 4. you have to use the "this" keyword
439
What are Getters and Setters at their very core?
They are methods/functions inside of an object that return values or set values that look like properties. object = { year: 1979 (this is an actual property/key value pair) get/set year( ) { some code that returns/sets 1979 (this is a function that runs and returns the value of 1979 as if it were the property) } } get obviously would return the value and set would obviously set the value
440
What is a good mental model for Getters and Setters?
An account log in list. When someone logs in, names are saved into an array value. This whole array can be shown at once, also the last person that logged in can be displayed. ``` class Account { constructor(allAccounts, username){ this.allAccounts = allAccounts; this.username = username; } set getAccount(updatedUserName){ this.username = updatedUserName; this.allAccounts.push(updatedUserName) ``` ``` } get getAccount(){ this.allAccounts = allAccounts; this.username = username; } } ``` let currentList = new Account([],"no username logged in yet"); ``` currentList.getAccount = "rmungo49@gmail.com"; currentList.getAccount = "JenanAbderrahman@gmail.com"; currentList.getAccount = "mungoRashaan@gmail.com"; currentList.getAccount = "baysauce35@yahoo.com" ``` console: ``` [ 'rmungo49@gmail.com', 'JenanAbderrahman@gmail.com', 'mungoRashaan@gmail.com', 'baysauce35@yahoo.com' ] baysauce35@yahoo.com ```
441
When calling a Getter or Setter function, what do we need to remember about calling the functions outside of the Class function?
We need to call them not like a function, but in the same way that we add a key/value pair to an object with dot/bracket notation. set function: currentList.getAccount = "rmungo49@gmail.com"; the value after the equal sign of this becomes the parameter of the set function (updatedUserName). ``` set getAccount(updatedUserName){ this.username = updatedUserName; this.allAccounts.push(updatedUserName) } ``` get currentList.username this returns the value of username on the object without actually accessing the original objects properties. ``` get getAccount(){ this.allAccounts = allAccounts; this.username = username; } ```
442
Before we can start Importing and Exporting different parts of code to be used in different files what do we first need to do to our HTML document?
We need to add a script tag with the type module with src of the main javascript file.
443
How do we Export a function so it can be used in other files?
export { function name}
444
Can you Export multiple functions at the same time?
Yes you can. All you have to do is separate the function name with a comma. export { function1, function2, function3}
445
How do you Import a function after it has been Exported? How do you import multiple functions at once?
Import {function name} from ./filename.js You can add multiple functions to a an import statement by adding it inside of the curly braces Import {function name, function name 2} from ./filename.js
446
What do we need to make sure that we have around the file name when we are using and Import Statement?
Quotations around the file name "./filename.js"
447
What do we do if we want to import ALL of the code from another file? What is the syntax? Whats different?
The main difference is the ---* as objectName --- instead of {function name} The name can be anything you want. This saves all the functions and code in one big Object. import * as myMathModule from "./math_functions.js";
448
When you have Imported all the code from another file and it is saved as an object, how do you access it in the new file ?
The same way you would access any other object. Dot/Bracket Notation. objectName.functionName(parameters) myMathModule.add(2,3); myMathModule.subtract(5,3);
449
When do we use Export Default?
When we are only exporting one value/function let iceCream = vanilla export default iceCream
450
Do you need the curly braces when using export default either Importing or Exporting?
No you do not, it is not necessary
451
When using Default Export, how can we IMPORT it under a different variable name?
Just Import it using the curly braces and 'default as variable name' import {default as newName} from "somefile.js" There will only be one default export from the file location so it will know which one to rename
452
What type of function is Promise?
It is a constructor function
453
What keyword do we need to make sure we use when creating a Promise?
We need to use the 'new' keyword because its a constructor function. const myPromise = new Promise((resolve, reject) => { });
454
What does a Promise take as an argument/parameter?
It takes a function with two parameters const myPromise = new Promise((resolve, reject) => { });
455
What are the three states of a Promise?
Pending, Fulfilled and Rejected.
456
What does the calling of the Resolve argument inside a Promise trigger? What does the Reject argument trigger?
Resolve => the Then method following it. Which tells us what to do with successful data or value we achieved in the resolve function. Reject => the Catch method following it. This tells us that our promise was unsuccessful and will either retry the call, do something else, or tell the user there was an error
457
Whats a conceptual difference between a Promise and an If/Else statement?
Promises are promises. They are things that need to happen, there is weight to whether they do their job or not. If you have a webpage that prominent functionality that depends on the data of an outside APi or something, your app needs to get that information. It is a promise, like 'Ill promise to be to work on time' and if that promise isnt fulfilled - you need a way to handle it. An If/Else statement is basically just a lower level example of this... where the functionality of the app isnt dependent on this working. If you have an If/Else statement that says if this number is even...do this.. but if its odd, do this...isnt going to break the code. It isnt weighted... it isnt a promise ...life will go on
458
When is a good time to use Promises?
When you have something thats going to take a minute to happen, like download a picture from a different server or perform an API call and you dont want all the code to stop running waiting for that to finish. This way you can keep running the rest of the code and whenever the promise gets what its looking for, it will bring it back and perform a function on it. This is why its called a promise, because the rest of the code is going on without it - with the expectation that it will come back with what its looking for.
459
What is the basic syntax of the Promise?
``` const myPromise = new Promise((resolve, reject) => { if(condition here) { resolve("Promise was fulfilled"); } else { reject("Promise was rejected"); } }); ```
460
What can we pass in the parens of Resolve or Reject?
We can pass anything we want, a function - a string - a number. Anything.
461
When adding a Then/Catch method do we chain them or code them separately?
We chain them then( ).then( ).catch( )
462
What are Regular Expressions?
Regular expressions are special strings that represent a search pattern
463
What are Regular Expressions?
Regular expressions are special strings that represent a search pattern. They are used in programming languages to match parts of strings. You create patterns to help you do that matching.
464
What is the test( ) method and what does it do?
It is added to the end of a Regular Expression or Regular Expression Variable and takes a String or Variable String and checks to see if that string has that text pattern. regEx.test(string) let testStr = "freeCodeCamp"; let testRegex = /Code/; testRegex.test(testStr); // Returns true
465
What type of value does the test( ) method return?
It returns a Boolean
466
What is the Regular Expression /string/ ?
Whatever is in between the slashes is checked for in the larger string when used with the .test( ) method. "the dog is running fast" /dog/ would return true
467
Is the test( ) method case sensitive?
Yes it is. A search for /Kevin/ would not return a true boolean for KEVIN or kevin
468
How can you search for more than one string using the test( ) method?
you can use the OR Operator | in between different strings patterns you want to search for. /yes|no|maybe/ this would search for the strings of yes no or maybe.
469
How can we search for a string pattern using the test( ) method while ignoring the case of the string?
You can add the " i " flag to tell the method to ignore the case. /ignoreCase/i this would return true for any combination of ignoreCase IGNORECASE ignorecase etc
470
What does the match( ) method do?
The match method is the opposite of the test( ) method. It extracts the actual matched value of the string and returns it. The match method is applied to the string and the Regex is added withing the parens of the match( ) method.
471
What does the match( ) method do?
The match method is the opposite of the test( ) method. It extracts the actual matched value of the string and returns it. The match method is applied to the string and the Regex is added within the parens of the match( ) method.
472
Can the match method( ) be attached to the actual string itself or can it only be added to the a string already stored in to a variable name?
The method can be applied to the string itself as well as a variable name. "Hello, World!".match(/Hello/);
473
How do we search for more than one pattern in a string?
We can use the "g" flag along with the match( ) method. let testStr = "Repeat, Repeat, Repeat"; let repeatRegex = /Repeat/g; testStr.match(repeatRegex); // Returns ["Repeat", "Repeat", "Repeat"]
474
What does the "g" flag return?
It returns an array consisting of the amount of times a pattern was found inside of a string. let testStr = "Repeat, Repeat, Repeat"; let repeatRegex = /Repeat/g; testStr.match(repeatRegex); // Returns ["Repeat", "Repeat", "Repeat"]
475
Is it possible to chain flags on the end of Regular Expressions?
Yes you can /twinkle/gi this would search for every instance of the word 'twinkle' in a string regardless of the case -- and add it in an array and return it
476
What is the Wildcard Period and how do we use it?
The Wildcard period is just a normal period but you use it in Regular Expressions to replace a character that you might not actually know or want to specifiy. ``` let humStr = "I'll hum a song"; let hugStr = "Bear hug"; let huRegex = /hu./; huRegex.test(humStr); // Returns true huRegex.test(hugStr); // Returns true ```
477
How can we match a character with multiple possibilities when using Regular Expressions?
You can place each character that you want to search for inside of brackets [ ]. This is called a Character Class. /b[aui]g/ this would search and return true for bag, bug, and big but wouldnt return true for bog, beg, bkg etc
478
What is a Character Set and How do we use them?
When you want to search for a range of characters using match( ) or test( ) methods in Regular Expressions you can use a hyphen between two characters and all of them in between will be searched for. This keeps you from having to individually type every letter you want to search for. Character sets are inclusive the the values you place on the book ends. 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 This works with numbers too. /[0-9]/
479
Can you search for both Numbers and Letters in a Character Set?
Yes you can. /[a-z0-9]/ig; This would search for all letters and all numbers.
480
What are Negated Character Sets? How do we apply them?
They are the same thing as normal character sets expect they specify characters that you dont want to match. You apply these with a ^ instead of a - The caret goes before the list of characters you want to exclude. Anything other than these characters will get matched including symbols and whitespace. /[^aeiou]/gi This will match everything except for vowels.
481
How can you find characters that appear ONE OR MORE times in a row?
you can use the addition operator after the character. -If the character is there just once it will return just the character /a+/ = "a" -if the character is there more than once it will return the original and the repeated characters. /a+/ = "aa"
482
What's the Regular Expression to check to see if something occurs in a string Zero or more times?
The start symbol *
483
What is a Greedy Match when referring to Regular Expressions?
It means that by default Regular Expressions search for the longest possible match in the string that properly validates. For Example /t[a-z]*i/ in the string titanic would return titani as opposed to "ti" which would also fit the criteria of the expression.
484
Regular Expressions by default are Lazy or Greedy?
Greedy
485
What is Lazy Match and how do we apply in when using Regular Expressions?
It returns the shortest possible valid string pattern you add a question mark /[a-z]?
486
How do we search for a character pattern at the beginning of a string with Regular Expressions?
You can you use the ^ outside of a character set and it will do this? /^Ricky/
487
How do you search for a character pattern at the end of a string in Regular Expressions?
You add a dollar sign at the end of a string /Ricky$/
488
What is the \w shortcut mean when using Regular Expressions?
It basically returns true for all numbers and all letters of the alphabet and also the underscore. /\w+/
489
What is the \W shortcut mean when using Regular Expressions?
It returns everything BESIDES numbers and letters and underscore.. Its the opposite of \w
490
How do you search for just Numbers in Regular Expressions?
\d
491
What do we need to remember about searching for character patterns in Regular Expressions? How many do they return.
By default, these do not return all or more than one matching characters. You have to specify if you want it to find all the instances or multiple instances. In general they return the first one they find
492
How do you search for everything besides numbers in Regular Expressions?
\D
493
What is /s in Regular Expressions?
It the way you find the white space in a string.
494
What is the /S in Regular Expressions?
It returns everything besides whitespace (spaces, tabs, new lines etc)
495
How do you set the range of characters that you want to search for inside of a string using Regular Expressions?
{minimum amount, maximum amount } /a{3, 8}/ this will look at the expression and see if there are a number of a's between the quantities of 3 and 8. So two a's return a false, 6 a's return a true.
496
How do we set a minimum number of characters that you want to search for inside a string using Regular Expressions?
Just set the minimum value /Haz{4,}ah/ this would return a true for Hazzzzah Hazzzzzah Hazzzzzzah or any combination of hazah that has more than 4 z's
497
How do we set an exact number of characters that you want to search for inside a string using Regular Expressions?
You simply place a number inside of curly brackets /Tim{4}ber/ returns true for Timmmmber
498
How do you say a certain character is optional when using Regular Expressions?
You can apply a ? before a character and it makes it optional /favou?rite/ /colou?r/ This will turn true for favourite or favorite and color and colour
499
What is a Lookahead in Regular Expressions?
Lookaheads are patterns that tell JavaScript to look-ahead in your string to check for patterns further along. This can be useful when you want to search for multiple patterns over the same string
500
What is a Positive Lookahead?
A positive lookahead will look to make sure the element in the search pattern is there, but won't actually match it. A positive lookahead is used as (?=...) where the ... is the required part that is not matched. let quit = "qu"; let quRegex= /q(?=u)/; quit.match(quRegex); // Returns ["q"] This returns true, because it looks ahead to the U and sees that there is one, so its true --But it doesnt return the U, it just makes sure that its there.
501
What is a Negative Lookahead?
On the other hand, a negative lookahead will look to make sure the element in the search pattern is not there. A negative lookahead is used as (?!...) where the ... is the pattern that you do not want to be there. The rest of the pattern is returned if the negative lookahead part is not present. let noquit = "qt"; let qRegex = /q(?!u)/; noquit.match(qRegex); // Returns ["q"] This returns true, because it looks ahead to see if there is a U and sees that there isnt one, so its true --But it doesnt return the U or the T , it just makes sure that it isnt there.
502
In a Character Set in Regular Expressions what does a dot represent?
A regular Dot. A literal Dot. Outside of character sets it represents any character, but inside the brackets it just represents itself
503
How can we use Escape in Regular Expressions?
The same way we would use them in quotations for strings with a \
504
The dash character can mean two different things inside a character set. What are these two things?
If it is the first thing in a character set it represents itself, a dash literal [ - . ] if its not the first character in a character set then it represents a range. [A - Z]
505
You can use the Pipe Operator to mean OR when using the .test( ) method to choose between various values in Regular expressions. How can you use this same functionality when writing longer Regular expressions?
When writing longer Regex, you can add parens around the terms using the pipe operator [a-zA-Z][0-9](gmail | yahoo | hotmail) the parens separate it from the rest of the expression so it can work. this isnt needed when its the only expression being hard coded straight into the test( ) method. Test already has parens that the pipe operators and values already go inside of test( yes | no | maybe)
506
What happens when your Regex finds a match as far as grouping?
It saves the whole string to the computers memory. It groups it all together.
507
What happens when you use parens inside your Regex code as far as grouping?
Additional groupings occur, meaning that the computer stores memory of that part of the string separately in addition to the original string. so [a-z]([a-z})([0-9]) creates three groups..... group 0 - the whole string group 1 - the first paren group to the right group 2 - the next paren group to the right
508
How can you access groups of code when grouped by Regex?
You can use backslash and a number \1 will be the first group with parens left to right \2 will be the second etc ``` let repeatStr = "regex regex"; let repeatRegex = /(\w+)\s\1/; repeatRegex.test(repeatStr); // Returns true ```
509
How can you use replace( ) with Regex?
You can search and replace text in a string using .replace() on a string. The inputs for .replace() is first the regex pattern you want to search for. The second parameter is the string to replace the match or a function to do something. let wrongText = "The sky is silver."; let silverRegex = /silver/; wrongText.replace(silverRegex, "blue"); // Returns "The sky is blue."
510
How do we remove whitespace ONLY from the beginning and end of a string using a method and using regex?
let hello = " Hello, World! "; let wsRegex = /^\s+|\s+$/g; // Change this line let result = hello.replace(wsRegex, ""); // Change this line trim( ) does this without regex using regex /\s+/g will remove spaces everywhere in the string
511
What are the three general types of errors and what do they mean?
syntax errors that prevent a program from running runtime errors when code fails to execute or has unexpected behavior semantic (or logical) errors when code doesn't do what it's meant to.
512
What habit should we get into in putting console.log( ) in our code.
Every function should have a console.log, this will help with keeping track with what's happening in your code
513
What is console.clear( ) and how can we use it?
Constantly using console.log( ) will make your console cluttered and hard to read whats going on. You can strategically place console.clear to clear the console without getting rid of the console logs so you can them there in case a problem arises later
514
What data type are arrays technically?
They are objects technically
515
What type of error is a Reference 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 - JavaScript variable and function names are case-sensitive.
516
When using push or unshift on an array to add another array how will the array be produced?
As a multi-dimensional array. ----adding array literal with push: ---- array = [1,2,3] array.push([4,5,6]) produces [1,2,3[4,5,6]] ----adding array stored in an array with push: ---- array = [1,2,3] storedArray = [4,5,6] array.push(storedArray) produces {1,2,3[4,5,6]]
517
When using push or unshift on an array to add individual items not in an array how will the array be produced?
as a one-dimensional array ---adding individual literal values with push: ---- array = [1,2,3] array.push("four",5,"six") produces [1,2,3,"four",5"six")
518
What is the only way that you can use push( ) or unshift( ) on an array and not have it become a multidimensional array?
by adding items not as an array inside of the unshift( ) or push( ) - you can add as many items as you want inside of the parens array = [1,2,3] array.push("four",5,"six") produces [1,2,3,"four",5"six")
519
What do we use to remove elements from an array?
splice( ) this allows us to remove any number of consecutive elements from anywhere in the array
520
How many parameters does splice( ) take?
It can take up to three.
521
What is the first parameter of splice( ) represent?
it represents the starting position. Remember this uses zero based indexing so the first one starts at zero.
522
What does the second parameter of splice( ) represent?
It represents how many total items we want removed from the array. let array = ['today', 'was', 'not', 'so', 'great']; ``` array.splice(2, 2); // remove 2 elements beginning with the 3rd element // array now equals ['today', 'was', 'great'] ```
523
What does splice( ) return?
A new array of the removed items. It represents how many total items we want removed from the array. let array = ['today', 'was', 'not', 'so', 'great']; ``` array.splice(2, 2); // remove 2 elements beginning with the 3rd element // array now equals ['today', 'was', 'great'] ``` slice returns ['not', 'so']
524
What is the third parameter of splice( ) ?
The third parameter is used to add items to an array after you have removed elements from an array.
525
How many arguments does the third parameter of splice( ) take ?
It can take as many arguments as you want as long as they are separated by a comma. ``` const numbers = [10, 11, 12, 12, 15]; const startIndex = 3; const amountToDelete = 1; ``` numbers.splice(startIndex, amountToDelete, 13, 14); // the second entry of 12 is removed, and we add 13 and 14 at the same index console.log(numbers); // returns [ 10, 11, 12, 13, 14, 15 ]
526
What does the slice( ) method do?
It copies particular elements of an array and copies them to a new array without modifying the original array.
527
How many parameters does slice( ) take?
It takes two.
528
What do the parameters of slice( ) do?
The first one is the starting point of where the copying of the array will begin (zero indexing). The second one is the point that you want the copying to stop. This is non inclusive, so whatever point you put as the stopping place will not be included. So add one more to the last element you want in the array. let weatherConditions = ['rain', 'snow', 'sleet', 'hail', 'clear']; ``` let todaysWeather = weatherConditions.slice(1, 3); // todaysWeather equals ['snow', 'sleet']; // weatherConditions still equals ['rain', 'snow', 'sleet', 'hail', 'clear'] ``` notice that the stopping point was 3 which in the array = hail but the last item copied is sleet which is the element before 3.
529
How can you completely copy an array? Do you need to use splice( )?
YOU DONT NEED SPLICE!!! just use the spread operator. ``` let thisArray = [true, true, undefined, false, null]; let thatArray = [...thisArray]; <= <= <= <= EXAMPLE // thatArray equals [true, true, undefined, false, null] // thisArray remains unchanged, and is identical to thatArray ```
530
How can we search an array for a particular element and get it to return the index of that element?
array.indexOf( "element" ) let fruits = ['apples', 'pears', 'oranges', 'peaches', 'pears']; fruits.indexOf('oranges'); // returns 2
531
When using array.indexOf( ) on an element and the element isnt present in the array, what will it return?
-1
532
What does the every( ) method do on an array?
The every( ) method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value. const isBelowThreshold = (currentValue) => currentValue < 40; const array1 = [1, 30, 39, 29, 10, 13]; ``` console.log(array1.every(isBelowThreshold)); // expected output: true ```
533
What can you iterate through the keys of an object? And what is the syntax?
with a 'For ..... In' loop. for ( let newVariable name In nameOfObject) { what do you want to happen in loop } users = ['Alan', 'Jeff', 'Sarah', Ryan'] for (let user in users) { console.log(user); } ``` // logs: Alan Jeff Sarah Ryan ```
534
How can we use a 'counter' variable to count how many times something happens in a function when using a loop?
Create a variable that equals 0 and when the code executes whatever you want, or finds a true value or whatever it is your looking for and increase the variable name by 1 ++ ``` function countOnline(obj) { // change code below this line let result = 0; for (let user in obj) { if (obj[user].online === true) { result++; } } return result; ```
535
What is Object.keys( ) and what does it return?
it returns an array consisting of the keys of an object. return Object.keys(obj) [ 'Alan', 'Jeff', 'Sarah', 'Ryan' ]
536
How do we turn an array into a string without commas?
.join(' ')
537
Which are two ways in which you can reverse a string?
1. ``` function reverseString(str) { let reversedStr = " "; for( let i = str.length - 1; i >= 0; i--){ reversedStr += str[i] } console.log(reversedStr) return str; } ``` 2. ``` function reverseString(str) { return str .split("") .reverse() .join(""); } ```
538
What does split( ) do?
Split( ) takes a string and turns it into an array of substrings ('') will separate every character by a comma. (" ") will separate every word with a comma, or where ever there is a space.
539
What does .reverse( ) do ?
reverse will reverse the order of the items inside of an array.
540
What is a short concise way to find the longest string in an array?
``` function findLongestWordLength(str) { return Math.max(...str.split(" ").map(word => word.length)); } ```
541
What does .sort( ) do? and what is the default?
It sorts the items of an array. By default it sorts strings alphabetically
542
How does sort( ) work with numbers?
Sort sorts numbers not by the value they represent but by individual digits... so 25 would come before 100 because the digit of 2 is higher than 1 in the first place of the hundreds place
543
What is reduce( )?
The reduce( ) method reduces the array to a single value.
544
What does find( ) do?
The find( ) method returns the value of the first element in an array that pass a test (provided as a function).
545
What does filter( ) do?
The filter( ) method creates an array filled with all array elements that pass a test (provided as a function).
546
What does the replace( ) method do?
The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced. Return a string where "Microsoft" is replaced with "W3Schools": ``` var str = "Visit Microsoft!"; var res = str.replace("Microsoft", "W3Schools"); ```
547
What should we note and remember about the | replace( ) method?
That it only replaces the first instance of the matched expression if using a string as a replacement.
548
How do we take a string and make the first letter capitalized?
``` function titleCase(str) { var convertToArray = str.toLowerCase().split(" "); var result = convertToArray.map(function(val) { return val.replace(val.charAt(0), val.charAt(0).toUpperCase()); }); return result.join(" "); } ``` titleCase("I'm a little tea pot");
549
What does charAt( ) do?
it returns the character at that specified place in the index, which is placed in the parens. Return the first character of a string: ``` var str = "HELLO WORLD"; var res = str.charAt(0); ```
550
How can we find out if a data type or variable name has a Boolean of truthy or falsy?
Boolean(variableName) this will return a true of the data type is truthy will return a false when the data type is falsy null, undefined, false, an empty string, 0 or NaN
551
Whats the difference between indexOf( ) and | findIndex( ) ?
indexOf( ) can be used by just adding the value or name inside the parens. It will search the array or the string for it and return the index. findIndex( ) is used to pass a function inside of the parens, this can be used to find an item in which you dont already know the variable name or whats in the array, or want the first of many possible items of an array.
552
What does includes( ) do?
The includes() method determines whether an array contains a specified element. This method returns true if the array contains the element, and false if not. Note: The includes() method is case sensitive.
553
Why do we use the 'this' keyword in a object method?
We use it when we want to access another property of the object. ``` let dog = { name: "Spot", numLegs: 4, sayLegs: function() {return "This dog has " + this.numLegs + " legs.";} }; ``` This allows us to
554
Why should we use the this keyword for Dot Notation in object methods?
Because sometimes we need to change the name of objects and if the object of the name changes we dont want the code to break when we call the object method
555
What are object key values that are functions called?
They are called methods
556
What are constructors?
Constructors are functions that create new objects. They define properties and behaviors that will belong to the new object. Think of them as a blueprint for the creation of new objects.
557
How do we visually distinguish constructor functions from other types of functions?
They start with a capital letter and they set properties using this keyword
558
What is the name for when a Constructor creates a new Object?
Its called an Instance
559
How can we figure out if a object was created by a particular Constructor?
the instanceof operator. instanceof allows you to compare an object to a constructor, returning true or false based on whether or not that object was created with the constructor crow instanceof Bird; // => true
560
What are Own Properties?
Own Properties are properties that are defined in the object themselves, either through hardcoding the properties yourself or through the use of a constructor function. Both are considered Own Properties
561
If you have an object that will have a set property for all instances of the object, how can we set that property so we dont have to keep repeating it. Like a name property for a lot of people objects.
By using prototype Properties in the prototype are shared among ALL instances of the objects that a Constructor creates. Bird.prototype.numLegs = 2; Now all instances of Bird have the numLegs property. console. log(duck.numLegs); // prints 2 console. log(canary.numLegs); // prints 2
562
When you assign a Object Property to a Constructor using Prototype do you do it inside or outside of the Constructor function?
It doesnt matter, it will take affect anywhere you declare it
563
Are Prototype Properties and Own Properties the same?
No. You will not see the Prototype Properties when you print out or console.log the the Object Name. It is applied to the object behind the scenes and is technically apart of the constructor that constructs the object and not the object itself.
564
If we cant see Prototype Properties on the actual object themselves or when we console.log the object, how do we access it or see it?
using dot/bracket notation pitBull.prototype.name = "Spot"
565
How can we add all Object Properties, whether Own or Prototype to a new array?
with an if/else statement if own props are found => push to new array else if prototype props are found => push to same array return array
566
What is a Constructor Property? How can it be used? What is it similar to?
A constructor property can be used to check to see if a object was made by a particular constructor function. Will return a boolean. spot. constructor == Dog => true this is similar to the instanceof keyword
567
Is it better to use the constructor or the instance of keyword to check if an object was made by a particular constructor?
Its better to use instanceof because constructor can be overwritten
568
Instead of creating individual Object Prototype Properties how can we add more than one at a time?
You can add all the prototype value/keys to a prototype object. ``` Bird.prototype = { numLegs: 2, wings: 2, beak: 1, eat: function() { console.log("nom nom nom"); }, describe: function() { console.log("My name is " + this.name); } }; ```
569
What is a crucial side effect of setting a prototype object?
It erases the constructor property
570
How do we need to do to counteract a Prototype Object erasing the Constructor Property?
we set the constructor property and the value in the Prototype Object. ``` Bird.prototype = { constructor: Bird, // define the constructor property numLegs: 2, eat: function() { console.log("nom nom nom"); }, ```
571
What does isPrototypeOf( ) do?
``` 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);
572
Do all Objects have Prototypes?
Not all but Most
573
A Prototype in its essence is what?
It is an object
574
Can Prototypes also have Prototypes?
Yes they can Because a prototype is an object, a prototype can have its own prototype! In this case, the prototype of Bird.prototype is Object.prototype: Object.prototype.isPrototypeOf(Bird.prototype); // returns true
575
A Object made by a constructor is what in relation to the ConstructorFunctionName.Prototype?
It is the child, its lower than it on the chain. the object of 'alex' and the object of 'dave' are both children and inherit properties from Person.prototype if Person.prototype.species = human all objects coming out of person would take the property species : human
576
How can we override the properties in the prototype object connected to our objects?
We use bracket and dot notation to apply new key/value pairs to our objects. for example Initial set => taking value from prototype ``` Person {name: "Sarah", age: 16} age: 16 name: "Sarah" __proto__: fingers: 10 <= passed in from set prototype ``` Overriding with Dot Notation sarah.fingers = 8; Person {name: "Sarah", age: 16, fingers: 8} age: 16 fingers: 8 <== this will show up when you run it name: "Sarah" __proto__: fingers: 10
577
What is at the top of the Prototype Chain?
At the very top Object.prototype is at the top...everything runs up and comes from this.
578
What does DRY stand for? Why is this principle important?
Don't Repeat Yourself. If you change something you have to change it in all the places. Also, more times you have to write the same code the more likelihood for bugs and more work for yourself and for others.
579
If two prototypes share the same key/value what should we do in What spirit of DRY?
Create a superType and place the shared key/value there. These both have the same 'eat function' ``` Bird.prototype = { constructor: Bird, describe: function() { console.log("My name is " + this.name); } }; ``` ``` Dog.prototype = { constructor: Dog, describe: function() { console.log("My name is " + this.name); } }; ``` We should make a supertype called animal and add the eat function to it and remove it from the other prototype objects function Animal() { }; ``` Animal.prototype = { constructor: Animal, describe: function() { console.log("My name is " + this.name); } }; ```
580
What is Inheritance when referring to Object Oriented Programming?
Its receiving properties and data from objects and constructors without having to hard code it yourself. It then can be modified or changed without changing the original properties or values
581
When an object inherits its prototype from another object, it also inherits what?
When an object inherits its prototype from another object, it also inherits the supertype's constructor property.
582
How do you reset a constructor property after you've used inheritance?
Bird.prototype.constructor = Bird;
583
How do we set up Inheritance in Objects between parents and child?
function Animal() { } ``` set parent and give prototypes _______________________________________ function Bird() { } function Dog() { } ``` set sub objects and any hard coded key/values you want to have ________________________________________ ``` Bird.prototype = Object.create(Animal.prototype); Dog.prototype = Object.create(Animal.prototype); ``` bind children to parents prototypes ________________________________________ Bird.prototype.constructor = Bird; change back constructors of children objects ________________________________________ Add additional methods or properties you want that specific sub object to have Dog.prototype.fly = false <= string example ``` Dog.prototype.facts = { <= object example city: 'Philly', type: 'Pitbull', friendly: 'Yes', owner: 'yes' } ``` __________________________________________ Create new specific instances with prepassed properties and now can add individual properties if you like ``` let duck = new Bird(); let beagle = new Dog(); ```
584
Can you override and inherited prototype ?
Yes you can, the same way you update or do anything in Objects. Dot Notation. Just use the same path and name and give it a new value. Animal.prototype.eat = function() { return "nom nom nom"; changed to Bird.prototype.eat = function() { return "peck peck peck"; };
585
When attempting to inherit data from objects to other objects, why is it important to make sure that you change and reset the constructor property?
If you do not, any time you try to add additional properties - it will make you choose one or the other (parent or child) to update. One overriding the other. If you set the parent, then change the constructor back to itself (child object) then you can add new methods and properties to the child element
586
When is inheritance not the best approach for object behavior sharing? What should be used instead?
When the objects are unrelated. An object representing Birds And an object representing Airplanes both fly but shouldnt use inheritance to share that behavior. Mixins should be used instead.
587
What is a Mixin? What does it do and what is the syntax for it?
A mixin allows other objects to use a collection of functions. ``` let flyMixin = function(obj) { obj.fly = function() { console.log("Flying, wooosh!"); } }; The flyMixin takes any object and gives it the fly method. ``` flyMixin(bird); flyMixin(plane); result bird. fly(); // prints "Flying, wooosh!" plane. fly(); // prints "Flying, wooosh!"
588
What is a Public Property?
It can be accessed and changed outside of the objects function.
589
What is a Private Property?
a property that can only be accessed and changed by methods also within the constructor function.
590
What is an example of code that you want to be Private instead of Public?
Account numbers, bank statements, social security numbers, passwords etc.
591
What is the simplest way to create a Private Property?
Create the variable inside of the constructor function. This takes the scope outside of global
592
What is a Privileged Method?
Its a method that has access to a private property inside of the same constructor function. let hatchedEgg = 10; // private variable ``` /* publicly available method that a bird object can use */ this.getHatchedEggCount = function() { return hatchedEgg; ``` here getHactchedEggCount is the Priveledged Method of the private property hatched egg
593
What is Closure when it comes to Private/Public Properties?
Closure is the act of setting a variable inside of a constructor method to make it private, and then creating a privileged method in the same constructor that is equal to the same value as the private property. This allows the value to be changed and manipulated from the outside without changing the actual data inside the function. let hatchedEgg = 10; // private variable ``` /* publicly available method that a bird object can use */ this.getHatchedEggCount = function() { return hatchedEgg; }; } let ducky = new Bird(); ducky.getHatchedEggCount(); // returns 10 ```
594
What is an Immediately Invoked Function and what does it do? What is the syntax?
It calls the function as soon as its declared. (function () { console.log("Chirp, chirp!"); })(); its basically a normal function with 4 main differences 1. No name 2. No variable 3. wrapped in extra parens 4. extra parens at the end
595
How are Immediately Invoked Functions usually used?
To group functionality inside of one object/module. For example two different mixins are placed under one variable name and is called immediately. This makes it so that all the information is not in an array and can be used ``` let motionModule = (function () { return { glideMixin: function(obj) { obj.glide = function() { console.log("Gliding on the water"); }; }, flyMixin: function(obj) { obj.fly = function() { console.log("Flying, wooosh!"); }; } } })(); ``` Now we can call motionModule.glideMixin(duck) or motionModule.flyMixin(dog) and assign these prototypes to these unrealted functions.
596
What is Functional Programming? What are its main three tenets ?
Functional programming is a style of programming where solutions are simple, isolated functions, without any side effects outside of the function scope. 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
597
What is a Callback Function?
Callbacks are the functions that are slipped or passed into another function to decide the invocation of that function. You may have seen them passed to other methods, for example in filter, the callback function tells JavaScript the criteria for how to filter an array.
598
Whats a First Class Function?
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
599
Whats a High Order Function?
The functions that take a function as an argument, or return a function as a return value are called higher order functions.
600
Whats a Lambda?
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.
601
What is Imperative Programming?
Telling the computer what to do and exactly how to do it
602
What is declarative Programming?
Telling the computer what you want done and less how you want it done
603
In functional programming what do we call changing or altering things?
Mutation
604
What are the effects of mutation called in Functional Programming?
Side Effects
605
What is an example of Mutation and a Side Effect?
``` // The global variable var fixedValue = 4; ``` function incrementer () { return fixedValue ++ ; } This causes mutation.... the side effect is that the global value is changed to 5 the better way is to go fixedvalue + 1 this keeps the global value the same and still has the function produces the desired result of 5
606
What Principal should we always adhere to when it comes to arguments in Functional Programming?
if a function depends on a variable or object being present, then pass that variable or object directly into the function as an argument. ``` var fixedValue = 4; function incrementer (x) { return x + 1; } ```
607
If you pass arrays as parameters and alter them with methods like push and shift, will the global array be effected?
Yes, they will be. So its important to copy the array even after you pass it in as an argument and then alter it ``` function add (list, bookName) { let newArr = list.slice(); newArr.push(bookName) ``` return newArr;
608
What does filter( ) return?
An Array containing all the array elements that pass the test. If no elements pass the test it returns an empty array.
609
What is an elegant way to add or remove an parameter from an array also passed in as a parameter?
``` function add(list, bookName) { return [...list, bookName]; } ``` ``` function remove(list, bookName) { return list.filter(book => book !== bookName); } ```
610
Map( ) returns what?
A new array
611
Map( ) has three arguments that it returns what are they?
1. element itself 2. index it takes in array 3. the whole array that map is being ran on
612
When pushing parts of an object into a new array can you rewrite the keys and just access the values through bracket or dot notation?
Yes you can. It is not neccesary to try and get the key to be the same or find a way to bring it with the value.... just write the key, or make a new one similar and then just use dot notation to bring over the important information to where you want it to be. [{"title":"Inception","rating":"8.8"},{"title":"Interstellar","rating":"8.6"},{"title":"The Dark Knight","rating":"9.0"},{"title":"Batman Begins","rating":"8.3"},{"title":"Avatar","rating":"7.9"}] if we wanted to loop through this and take all the movie titles to a new array.. you wouldnt need worry about the keys just create new keys like "MovieName" instead of Title push.({MovieName : object.title}) and this will do what you need it to do
613
Whats the difference between parseInt and parseFloat ?
parseFloat will keep a decimal number a decimal it will just turn it from a string to a number parseInt does the same thing but will make it an integer, decimal number get rounded down to the nearest whole number
614
What does the slice( ) method return?
It returns an extracted part of the array as a new array
615
does slice alter original array?
No it doesn't, it copies and returns a new array that you can save in a variable
616
does splice alter the original array?
yes it does, it returns what is removed and that can be save in a variable but the original array is also altered
617
concat( ) adds two strings or arrays together and creates a new array, does it affect the individual strings or arrays?
No the original variables stay unaltered. It just creates a new array that you can store in a new variable
618
What is concat( ) relationship to push( )?
They both add things to arrays, but concat does not alter the original array which mean its the preferred way as far as functional programming is concerned
619
How can you find out or check to see if a number is a float or an integer?
Number.isInterger( ) place the number in the parens and it will return a boolean with true or false
620
How do we find the square root of a number?
Math.sqrt( ) place the number in between the parens
621
When using sort( ) with strings do we need to add a compare function?
No, by default it will put it in alphabetical order. just put .sort( ) on the array
622
What is a compare function on sort( )?
It is the function that you have to use with numbers to make sure that it sorts the numbers correctly.
623
Does sort( ) change the items in the original array?
Yes it does.
624
Can Regular Expressions be used with Split( )?
Yes it can ``` var otherString = "How9are7you2today"; var byDigits = otherString.split(/\d/); // Sets byDigits to ["How", "are", "you", "today"] ```
625
What does \W represent in RegEx?
Any non word characters [numbers and symbols]
626
When we use join( ) what will be added between the words being joined together?
A comma
627
When using join( ) how do we specify what goes between the words?
Add them in the parens. If you want a space add a space .join(" ") if you want dashes add dashes .join(".") etc
628
What does the method some( ) do and what does it return?
its the opposite of every, it runs a function and checks to see if ANY of the items meet the criteria. it returns a boolean
629
What does Math.min( ) and Math.max( ) do?
Returns the highest and the lowest numbers in an array console. log(Math.min(...arr)) console. log(Math.max(...arr)) sumAll([1, 4]); 1 4
630
What two array methods can we use to see if an array has a particular element, value or item?
Index0f( ) = this will return the index of the item if found or an - 1 if not found includes( ) = will return a Boolean true/false depending on if the array has it or not.
631
If you need to run a function forwards and backwards do we need to write the function twice?
No, we should look to write the function in a way that we can call it once, and switch the parameters around to produce various results. INSTEAD OF --- this calls two functions preforming the same function on one array and then switches the order of the arrays starting with arr1 and then arr2 ``` function modify(arr1, arr2){ arr1.map(item => { return arr2.includes(item) ? null : newArr.push(item) }); arr2.map(item => { return arr1.includes(item) ? null : newArr.push(item) }) } ``` WE SHOULD DO --- this makes one function and switches the arguments ``` function modify(arr1, arr2){ arr1.map(item => { return arr2.includes(item) ? null : newArr.push(item) }); ``` Modify(first, second); Modify(second, first);
632
How do we add spaces or anything in between particular letters using Regex? Not substitute letters for white spaces or symbols, but to add spaces or symbols when they are not there?
1. use replace 2. create two groups with each group representing what you want to come before the space/symbol ([group1 ]) 3. the third group represents what you want to come after the space or the symbol ([group 2]) 4. add $1 and $2 to represent each group 5. place whatever you want to go in the space between to be in between $1/$2 group str.replace(/([a-z])([A-Z]/g, "$1 ! $2") this will place a ! in any place where a lowercase number is followed by a capital case letter
633
What does every( ) return and how does it decide what it returns?
It checks that every item in an array validates to true...if every item validates to true it returns a true.... if even one returns false then the whole thing is false.
634
What to remember about using the Rest Parameters when it comes to adding other parameters? When might it come in handy?
You can take the first items of an array and give them specific parameter names and then place all the other array items in an array by it self using the rest parameter operator/spread operator [1,2,3,4,5] function seperate(one, two, ...threeToFive) this will make three arguments 1 2 [3.4.5] This can come in handy when you need to do something with the first couple of elements but also be able to access unknown number of parameters
635
If you need to use concat( ) but dont have a second or third array in which to append .concat( ) on what can you do?
you can create an empty array array = [ ] and then use concat( ) on that and attach the array you want to use array.concat(otherarray)
636
Can you chain replace( ) methods together?
yes you can. ``` let gotit = str.replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'") .replace(/<>/g, "<>"); ```
637
How What is an algorithm to find if a number is a Prime Number?
``` function isPrime(num) { if(num < 2) return false; for (var i = 2; i < num; i++) { if(num%i==0) return false; } return true; } ```
638
When using Recursive Functions with multiple parameters, do we need to make sure that all our parameters are inside the Recursive Case?
Yes we do. Otherwise it will throw a Reference Error/ Error ``` function recursiveFunctionName(arrayParam, numParam) THIS IS REGULAR CALL if ( numParam <= 0){ return; } else { arrayParam.push(numParam) console.log(arrayParam) return recursiveFunctionName(arrayParam, numParam - 1) THIS IS RECURSIVE CALL } } ```
639
If you're trying to create an array or add to an array using a Recursive Function how would you create/access or accomplish this?
Create an empty array outside of the function and pass it through the Recursive Function by passing it in as an argument. ``` function recursiveFunctionName(arrayParam, numParam){ ARRAY PARAM IS THE ARG. if ( numParam <= 0){ return; } else { arrayParam.push(numParam) ARRAY PARAM IS THE ARG. console.log(arrayParam) return recursiveFunctionName(arrayParam, numParam - 1) ARRAY PARAM IS THE ARG. } } ```
640
What do you do if you have an if statement and you want nothing to happen if a certain condition is met? Instead of returning null.
You can just place the Return Keyword. ``` function recursiveFunctionName(arrayParam, numParam){ ARRAY PARAM IS THE ARG. if ( numParam <= 0){ return; } ```
641
In an Recursive Function -- inside of the Else Statement -- does the Recursive Call need to be the only code inside of it? Does any action we want to happen have to be linked to the Recursive Call itself?
No, it doesnt. The call just needs to be there to keep the loop going. But other types of code can be added to and performed inside of the Else Statement. The Recursive Call should go last. ``` else { arrayParam.push(numParam) console.log(arrayParam) return recursiveFunctionName(arrayParam, numParam - 1) } ``` I dont need to try and console and push and call the Recursive Function all in the same line of code.
642
In the Recursive Call what do we need to make sure that we have to make sure that the Base Case will eventually be reached and we will avoid a circular loop?
We have to adjust the Argument that is being passed through the function and being compared against the BaseCase so that every time the Recursive Function is called it gets closer to being terminated ``` else { arrayParam.push(numParam) console.log(arrayParam) return recursiveFunctionName(arrayParam, numParam - 1) <=== } ``` NUMPARAM IS BEING SUBTRACTED BY 1 EVERY TIME IT IS CALLED.
643
When trying to add second and third parameters to Javascript methods like map( ), what do we need to remember about some of them?
Some methods like map( ) already come with set meanings of what a second and third parameter represent. For example, map( ) second parameter is assigned to the index of what the first parameter is. So if you try to assign it to a function or give it some other use - it wont work, or will work in a way that you dont want. array.map(element, index) so if you did something like array.map((a, b) => a + b) it would produce something like apples0, banana1, fork2 because you will just be adding the element to its index number. so if you want to use some sort of other parameter function you should probably declare it somewhere else and use it inside of the map. array.map(element => [element, functionName(element)]) this would run a particular function on each element of an array and return the original element and the new value inside of a nested array example original array [A, B, C, D] [[ A, ABC] , [B, BBC], [C, CBC], [D, DBC]]
644
How to take a value as a parameter and add all the sums of every Prime Number less than it and return the value.
``` function sumPrimes(num) { let primes = [2]; // set up a new array, starting with 2 because we know that we are going to need that there and that 2 is the smallest prime number and the only even prime number, so we just set it because its the only one of its kind. ``` for(num; num >= 3; num--){ ``` // set up a loop that counts down the value of the parameter num // also sets it up so the loop stops before it reaches 2, which was hardcoded ``` ``` let i = 2; let numArr = []; while( i < num){ numArr.push(i) i++ } // this sets up an array, that counts from 2 up until the number before the value of num ``` ``` let check = numArr.some(item => { return num % item == 0 }) // This goes through numArr that consists of all the numbers from 2 until the value of num and takes each number and uses % to see if it returns a value of 0. If it returns a value of 0 anywhere along the way, it isnt a prime number. If not it is a prime number. This takes the boolean and stores it in the variable 'check' ``` check ? null : primes.push(num); ``` // this says if 'check' equals true than do nothing. If it is false then take // the value of num, and add it to the 'primes' array. } // <=== end of loop ``` ``` let total = primes.reduce((sum, num)=> { return sum + num }) ``` // this takes all the values inside of the prime array and adds them together using reduce and stores that in the variable 'total' return total //returns total outside of the function }
645
What is BootStrap?
Bootstrap is a front-end framework used to design responsive web pages and web applications. It takes a mobile-first approach to web development. Bootstrap includes pre-built CSS styles and classes, plus some JavaScript functionality. Bootstrap uses a responsive 12 column grid layout and has design templates
646
To get started with Bootstrap what should you first do?
Create a DIV with the CLASS of Container-Fluid that will nest other html elements
647
If we wanted to add an image that is exactly the width of our phone's screen what class would we add in Bootstrap?
'img-responsive'
648
How do we center text in Bootstrap?
By adding the 'text-center' class to an html element
649
How do you add a bootstrap style of button to your page?
By adding the classes 'btn btn-default' to the button element
650
Bootstrap buttons have what width by default?
They have the width of the content inside the button... | ie 'Like' or 'Submit'
651
How do we get the button to take up the entire space allotted horizontally?
We need to turn in into a block element and we do this by adding the class btn-block so our button would look like this Like
652
what does adding btn-primary do when you add it to a bootstrap button instead of btn-default?
it makes it facebook blue
653
what does adding btn-info do when you add it to a bootstrap button instead of btn-default?
it makes it twitter blue
654
what does the bootstrap button class btn-danger do?
it turns the button red and lets the user know that the buttons performs a destructive function
655
What two things do you need to do to put bootstrap elements in a row?
1. nest all elements you want horizontal in a row inside a div with a class of 'row' 2. specify how wide you want the elements to be by nesting the elements individually in a div while using the class 'col-screensize- width'
656
How do you specify the width and the screen size of item put into a bootstrap row?
col-screen size- width col-md-4 this would tell the element when the screen is medium sized to take up 4 of the 12 available columns. (so basically be one third of the available space) col-xs-2 this would tell the element when the screen is extra small to take up two of the 12 available columns - so basically take up 1/6th of the available space
657
What do we need to remember about bootstrap grids and how many columns it uses?
They work off a 12 column grid and so the number on the end of col-screensize-width represents how many of those 12 columns will be taken up by the element. ``` 12 equals all 8 is 75% 6 equals half 4 equals a third 2 equals a sixth ``` etc
658
How can we change the color of text using bootstrap the same way that we can change the buttons?
use text instead of the word btn in the class text-primary text-danger text-info
659
We can use the element span to do what as far as styling?
We can next particular inline elements with span and then apply classes to them in bootstrap that will change the color of aspect of the element while keeping it an inline element
660
What is 'Font Awesome'?
Font Awesome is a convenient library of icons. These icons can be webfonts or vector graphics. These icons are treated just like fonts. You can specify their size using pixels, and they will assume the font size of their parent HTML elements.
661
How do we add Font Awesome icons to an element?
You add font icon classes to either an i element or a span element
662
How do you add an Info Icon and thumbs up icon? What are the classes?
fas fa-info-circle fas fa-thumbs-up attach these to either an i element or a span element.
663
What class do i add to an i element or a span element to add the paper plane icon?
'fa fa-paper-plane'
664
What does wrapping all your HTML content in a bootstrap div with the container-fluid class do?
It makes all of your content on the page responsive
665
What does the BootStrap Class 'Well' do?
Bootstrap has a class called well that can create a visual sense of depth for your columns.
666
What does the .css( ) Jquery method do?
it changes the Css of the selected element. It works just like css, but they both take quotes and there is a comma instead of a colon $('p').css('transform', 'capitalize') -- this will make all the text capitalized.
667
How do you use Jquery to disable a button or some other element that can be disabled?
add .prop('disabled', true) to the selector and it will be disabled
668
What does the .html( ) jquery method do?
it replaces the html and content of the selected element
669
What does the .text( ) jquery method do?
it replaces the text of the selected element and not the html. If html tags are used here, the tags would be rendered like normal text
670
What does .remove( ) do in jquery?
it removes an Html element completely
671
What does .appendTO( ) do in jquery?
it puts an element inside of a div. it can be used to move one element from one div to another or it can be used to place an element into a div for the first time
672
What does .clone( ) do in jquery?
it creates a copy of an element
673
What does .parent( ) and .children( ) do in jquery?
it allows you to access the parent or child of an element
674
What does element:nth-child(n) do in jquery?
``` It allows you to specify a particular child of an element if you have 5 children that all have the same class of 'item' ``` you would access the fourth one like this $('.item:nth-child(4)').css('color','blue') this will turn the fourth element of the 5 the color blue
675
What does :even and :odd mean in jquery and what do we need to keep in mind about it?
this allows us to choose the even or odd numbers of a child by selecting the class name and then adding :even or :odd after it in the jquery selector then you can do something with it $('.item:odd').color('blue') this will take all the elements with the class of item and find the ones that have odd number as a position and then turn them blue. we have to remember that eventhough we are choosing Odd - zero base indexing means that odds will be the second item (index 1) the fourth item (index 3) and so on. and evens will be the first item ( index 0) and the third item ( index 2)
676
What does SASS stand for? And what is it?
Syntactically Awesome StyleSheets.... it is a language extension of CSS.
677
What is SCSS?
It is s syntax of SASS, known as Sassy CSS. It is an extension of CSS. files using this syntax have the .scss extension.
678
How do you store variables in SASS?
you initialize it with a dollar sign followed by the variable name followed by colon and the css values. examples $main-fonts: Arial, sans-serif; $headings-color: green;
679
How do you use variables in SASS?
You would use it the same way as normal CSS except instead of manually typing the value, you just use the variable name instead h1 { font-family: $main-fonts; color: $headings-color; }
680
What is a good example of why you would want to use variables in CSS/SASS?
Because if you have 10 elements that all needs the color red you can set the color red as a variable and then apply it. That way if later you choose you want to change it to blue. You dont need to change 10 elements, you just change the variable and it will change everything.
681
How can you nest css rule sets using SASS?
Normal CSS: nav { background-color: red; } nav ul { list-style: none; } nav ul li { display: inline-block; } Nesting with SASS: nav { background-color: red; ul { list-style: none; ``` li { display: inline-block; } } } ```
682
What is a Mixin in SASS? And why do we use it?
A SASS Mixin is a way to set up CSS properties that might not work on particular browsers. We basically create a funciton(the mixin) that applies the css function to specific types of browsers, then we place the mixin on the css rule set whereever we want it instead of having to rewrite the whole mixin anytime. example of setting up a mixin ``` @mixin border-radius($radius){ -webkit-border-radius: $radius; -moz-border-radius: $radius; -ms-border-radius: $radius; border-radius: $radius; } ``` example of applying a mixin ``` #awesome { width: 150px; height: 150px; background-color: green; @include border-radius(15px) ``` }
683
Why would we need to use a SASS Mixin?
Newer CSS features take time before they are fully adopted and ready to use in all browsers. As features are added to browsers, CSS rules using them may need vendor prefixes. For Example -- ``` @mixin border-radius($radius){ -webkit-border-radius: $radius; -moz-border-radius: $radius; -ms-border-radius: $radius; border-radius: $radius; } ```
684
How do you use @if and @else in SASS?
They work the same way as If and Else statements in Javascript, but they are used with mixins and variables for example ``` @mixin text-effect($val) { @if $val == danger { color: red; } @else if $val == alert { color: yellow; } @else if $val == success { color: green; } @else { color: black; } } ``` ``` #box { width: 150px; height: 150px; background-color: red; @include box-color(success); <==== this is how it is called } ```
685
What is @for used for in SASS?
It creates a version of a For loop but it has two types of loops : a start to end loop and a start through end loop
686
What is the difference between a 'start to end' and a 'start through end' @for loop?
A 'start to end' loop is a loop that loops up until the end and does not include the last item. A 'start through end' loop loops from start and includes the end/last item
687
This is a @for loop in SASS, explain whats going on.. @for $j from 1 through 6 { .text-#{$j} {font-size: 15px * $j } }
@for -- this starts the loop syntax $j -- this makes a variable J that we are going to use from 1 through 6 -- this tells us the start and stop place of the loop .text- -- this is the start of the class of the element the styling will be applied to #{$j} -- this places the variable value on the end of the element class so it will in total be .text-1 .text-2 .text-3 and so on until it reaches 6. {font-size: 15px * $j } -- this is the actual styling. each element with the .text-# class will have the font-size increased by 15 * 1 and then 15 * 2 and then 15 * 3 etc.
688
This is an example of using @each with a list...what is happening here? @each $color in blue, black, red { .#{$color}-bg {background: $color} }
@each -- is the beginning of the iterating syntax $color -- is the created variable that we will use in blue, black, red -- is the created list we will iterate through .#{$color} -- is the first part of the string that will match the element's class, the its basically the same as back ticks variable in a string with an added # in SASS -bg -- this is the second part of the element's class that will be matched. {background: $color} -- this takes the iterated value and places it on the value of background this would iterate through the colors and apply them to the divs below and apply the background
689
What is the @while loop in SASS? What does this code mean? ``` $x : 1; @while $x <= 5 { .text-#{$x} { font-size: 15px * $x} $x: $x + 1; } ```
is works like a javascript while loop but it applies a styling while a condition is true $x: 1; -- this creates a variable and initiating it to the value of 1 @while $x <= 5 -- this sets the stop point of loop .text- -- this is the beginning part of elements class #{$x} -- this is the second part of the elements class that will also be the value of x.... so together it will be .text-1 .text-2 .text-3 etc {font-size: 15px * $x} -- this is the styling being applied to the element. It increases 15px by each multiple of x ...so 15px * 1 is 15 15px *2 = 30px ...etc $x: $x + 1 -- this increments the value of x at end of the code and before it loops, this allows it to reach the place to stop the loop so it doesn't become an infinite loop
690
What is REACT?
Intro: React is an Open Source view library created and maintained by Facebook. It's a great tool to render the User Interface (UI) of modern web applications.
691
What is JSX?
Its a syntax that allows you to write HTML directly into Javascript
692
When you want to write Javascript directly with JSX, where do we place the Javascript code?
within the curly brackets { 'this is treated as JavaScript code' }
693
What do we need to remember about Nested JSX?
JSX can only return one main element..usually meaning we need to wrap everything in a single div Valid JSX: ```

Paragraph One

Paragraph Two

Paragraph Three

``` Invalid JSX:

Paragraph One

Paragraph Two

Paragraph Three

694
How do you comment out in JSX?
The same way as normal but you have to also put it in curly brackets. so {/* */}
695
How do we render react elements/components to the DOM?
ReactDOM offers a simple method to render React elements to the DOM which looks like this: ReactDOM.render(componentToRender, targetNode), where the first argument is the React element or component that you want to render, and the second argument is the DOM node that you want to render the component to. ReactDOM.render(JSX, document.getElementById('challenge-node')) JSX here is variable name that holds html elements for example ``` const JSX = (

Hello World

Lets render this to the DOM

); ``` and challenge-node is the id of some element
696
Can we use the keyword class to define classes in JSX like you would in HTML?
No you have to use the word className Also note that CamelCase is the spelling convention that we use in JSX as opposed to all lower case in HTML
697
What is the difference in tags in HTML and JSX?
Any JSX tag can be self closing, even if it the HTML version of the tag cannot be. And any self closing tag must have a closing slash as well. Valid JSX div /div or div />
698
What is a Stateless Function in React? How do you create it? What does it return?
think of a stateless function as one that can receive data and render it, but does not manage or track changes to that data You create it with a normal Javascript function that returns JSX or null Valid Stateless Function: ``` const MyComponent = function() { return
This is a string
} ``` or ``` function MyComponent( ){ return
This is a string
} ```
699
What does a React Function name have to start with?
A capital letter
700
How do you create a React Component and what is the difference between it and a React Function?
A React Component extends the React.Component so the component itself has access to many useful React Features. A React Component has: 1. class keyword 2. extends React.Component after Name 3. constructor(props) 4. super(props) 5. render( ) 6. return
701
How do you render a Component inside another Component as a child?
To render a component as a child in a React component, you include the component name written as a custom HTML tag in the JSX. For example, in the render method you could write: return ( ) this would be if you created three different components named NavBar, Dashboard and Footer and placed them in the return section of a Component named App
702
How do you pass props to Child Components in React?
By passing the a created prop name and value when you nest it within the Parent Component and then applying props.createdpropname within the child component itself ``` Parent-- class CurrentDate extends React.Component render( ) { return (
<======
``` CurrentDate - name of child component date - created propname Date( ) - value of created propname Child -- ``` const CurrentDate = (props) => { return (

The current date is: {props.date}

); ``` props -- is the default name for passing props in child components .date == references the value that was applied in the Parent Component result: The current date is: Thu Aug 20 2020 09:05:17 GMT-0700 (Pacific Daylight Time)
703
How do we pass an Array as props into a Child Component?
you do it the same way as normal props passing except you wrap the array in curly brackets Then inside of the Child Component you can apply array methods to it ``` const List = (props) => { return

{props.tasks.join()}

}; ```
704
What are Default Props in React and how do you apply them?
Default props are props that will show up in the event that a prop is not specified. This is a prop that will be shown if one isnt provided. you apply it with the syntax of ComponentName.defaultProps = {createdPropName : 'prop value' } ShoppingCart.defaultProps = {items: 'items: 0'}
705
How do you override Default Props when you want to set a value in React?
you set it the normal way that you would if there wasnt a Default Prop set. Setting it in the normal will override the default props. This is the CHILD COMPONENT --------- ``` const Items = (props) => { return

Current Quantity of Items in Cart: {props.quantity}

} ``` This is setting the DEFAULT PROPS ----------- Items.defaultProps = { quantity: 0 } This is the PARENT COMPONENT OVERRIDING -------------- ``` class ShoppingCart extends React.Component { constructor(props) { super(props); } render() { return <== override } }; ```
706
When putting an Integer in JSX do we need to use qoutes?
No we dont need the quotes but we do need to put it in curly brackets {100}
707
What is PropTypes in React and how is it set up?
PropTypes allows you to verify that your Component receives the correct type of of prop (number, string, boolean, etc). You set it the same way that you set Default Props: ComponentName.propTypes = { createdPropName: PropTypes.type MyComponent.propTypes = { handleClick: PropTypes.string } if wrong type it will cause an error
708
When Using PropTypes what two types of data types have different spellings?
``` Function = func Boolean = bool ```
709
What is .isRequired when using PropTypes and what does it do?
.isRequired makes it so that the prop is neccesary for the component to run Items.propTypes = {quantity: PropTypes.number.isRequired}
710
In the later installements of React, Protypes is imported independently of React....how do you import it?
import PropTypes from 'prop-types';
711
How do we pass a prop from a class component to a child component that also happens to be another class component?
We do it the same we would if we were passing a prop to a stateless function, the only difference is when we access it from within the function we have to use the keyword this. so for a component class it would be accessed like this.props.createdname as opposed to a stateless function that would access its prop like props.createdname
712
When applying Default Props and PropTypes to a component --- on the left side of the assignment operator how do we write it? And on the right side of the assignment operator?
On the left side we write it in camel case MyComponent.defaultProps = MyComponent.propTypes = On the right side we write it Component style with each word being Capitalized = {name: PropTypes.func.isRequired}
713
How do you create State in a React Component?
you need to have a class component that extends React.Component and apply state inside of the components constructor method as an object: ``` class StatefulComponent extends React.Component { constructor(props) { super(props); this.state = { name: 'dat boi good' } ```
714
How do you render State in the User Interface?
Once you define a component's initial state, you can display any part of it in the UI that is rendered. If a component is stateful, it will always have access to the data in state in its render() method. You can access the data with this.state. If you want to access a state value within the return of the render method, you have to enclose the value in curly braces. ``` class MyComponent extends React.Component { constructor(props) { super(props); this.state = { name: 'freeCodeCamp' } } render() { return (

{this.state.name}

); ```
715
How can we render State by variable name?
store state in a variable name in the render section and then produce it after the return statement ``` class MyComponent extends React.Component { constructor(props) { super(props); this.state = { name: 'freeCodeCamp' } } render() { const name = this.state.name return (

{name}

); } ```
716
what method do we call to change the State of a React Component? and how and where do we call it?
we call setState( ) inside of a function before the render( ) method. ``` class MyComponent extends React.Component { constructor(props) { super(props); this.state = { name: 'Initial State' }; this.handleClick = this.handleClick.bind(this); } handleClick() { <== this is the function changing state this.setState({ name: 'React Rocks!' }) } render() { ```
717
How do you bind a function name to the 'this' keyword inside of a React Component?
place this.FunctionName = this.FunctionName.bind(this) inside of the constructor method ``` class MyComponent extends React.Component { constructor(props) { super(props); this.state = { text: "Hello" }; ``` this.handleClick = this.handleClick.bind(this) ``` } handleClick() { this.setState({ text: "You clicked!" }); ```
718
How do you apply the function that changes State to an element that you want changed? Lets say for example a button?
You place the event listener as an attribute and make the value of that attribute as follows {this.functionName} ``` handleClick() { this.setState({ text: "You clicked!" }); } render() { return (
Click <== EXAMPLE Me

{this.state.text}

); ```
719
how do you change the state of a component? Which method do you use?
You create a function and use this.setState( ) in it. inside of the set state method you pass a function
720
What parameters can you use inside of the setState( ) function?
You can use any parameters that you want but one for state and props are especially useful
721
Do we need to use the 'this' keyword inside of our setState( ) function
No you do not. ``` toggleVisibility(){ return this.setState(state => { return state.visibility = !state.visibility }) } ```
722
When we actually change the state of a Component inside of setState, how do we do so?
you access the state object with dot notation ``` class MyComponent extends React.Component { constructor(props) { super(props); this.state = { visibility: false }; // change code below this line this.toggleVisibility = this.toggleVisibility.bind(this) // change code above this line } // change code below this line toggleVisibility(){ return this.setState(state => { return state.visibility = !state.visibility }) } ```
723
What does event.target.value do?
it returns the value of the element that was targeted that triggered the event in the function and makes it accessible ``` handleChange(event){ this.setState({ input: event.target.value }) } ```
724
How would we make an input be updated from a components state instead of from the browser?
Take the state and make it the value of the value attribute and put it on the input element in addition to the function that changes state {} value = {this.state.input} <==== example this would come from this state which begins as an empty string ``` class ControlledInput extends React.Component { constructor(props) { super(props); this.state = { input: '' }; ```
725
Can you pass the 'STATE' of one component as a prop to one of its child components?
Yes you can. ``` class MyApp extends React.Component { constructor(props) { super(props); this.state = { name: 'CamperBot' <=== this is state } } render() { return (
```
); } }; ``` class Navbar extends React.Component { constructor(props) { super(props); } render() { return (

Hello, my name is: {this.props.name}

<== accessing state data passed as prop from parent
); } }; ```
726
What is unidirectional data flow in React?
State flows in one direction down the tree of your application's components, from the stateful parent component to child components. The child components only receive the state data they need
727
What is Separation of State Management and UI in React?
This states that complex stateful apps can be broken down into just a few, or maybe a single, stateful component. The rest of your components simply receive state from the parent as props, and render a UI from that state. It begins to create a separation where state management is handled in one part of code and UI rendering in another. This principle of separating state logic from UI logic is one of React's key principles. When it's used correctly, it makes the design of complex, stateful applications much easier to manage.
728
Can you pass functions down from a Parent component to a child component the same way you can pass a prop or a state in react?
yes you can. ``` class MyApp extends React.Component { constructor(props) { super(props); this.state = { inputValue: '' <=== state } this.handleChange = this.handleChange.bind(this); } handleChange(event) { <=== function that changes state this.setState({ inputValue: event.target.value }); } render() { return (
{ /* change code below this line */ } <== passing function as prop ``` ``` { /* change code above this line */ }
); } }; ``` ``` class GetInput extends React.Component { constructor(props) { super(props); } render() { return (

Get Input:

<== applying function of parent in the child after being passed as a prop
); } }; ```
729
What is a lifecycle method in react?
They are methods that allow you to perform particular functions at particular times in a components life, for example when it first runs, before they are rendered, before they update, before they receive props, before they unmount, and so on.
730
What is componentWillMount( )?
the code inside of it will run before the render method in a react component does
731
What is the best place to place to an API call or any other call that goes to the server inside of a React Component?
you place it inside of the componentDidMount( )
732
What is componentDidMount( )? And what happens when you put setState inside of it?
This method is called after a component is mounted to the DOM. Any calls to setState() here will trigger a re-rendering of your component. When you call an API in this method, and set your state with the data that the API returns, it will automatically trigger an update once you receive the data.
733
what does setTimeout( ) do?
sets a timer which executes a function or specified piece of code once the timer expires. ``` componentDidMount() { setTimeout( () => { this.setState({ activeUsers: 1273 }); }, 2500) this sets up a change of state that will take place after 2500 milliseconds which is 2.5 seconds. ```
734
What is the best place to add event listeners to your React Components? How do you do so?
Inside of componentDidMount( ) eventTarget.addEventListener(triggering event, function of what you want to happen); button.addEventListener('click', this.handleClick) this would make it so a button gets clicked the function handleclick will run
735
There are some already built in eventListeners in react like onClick or onChange that you can use as props for elements. Why then would you need to use eventTarget.addEventListener( ) ?
You would use this when you wanted to add event listeners to the document object or the window object.
736
What is the opposite of componentDidMount( ) and eventTarget.addEventListener( )?
componentWillUnmount( ) eventTarget.removeEventListener( ) they work exactly like their counterparts but remove instead of add
737
What does shouldComponentUpdate( ) do?
it returns a boolean and see if a prop has a new value, if it has a new value you can set it up so it returns true. If it returns true the code will keep running and will re-render. But if it turns false, it wont re-render. this keeps from unnecessary renderings when props or the state hasnt changed. This improves app performance. ``` shouldComponentUpdate(nextProps, nextState) { console.log('Should I update?'); if (nextProps.value % 2 == 0){ return true; } else { false; } } ``` {these functions will only run if shouldUpdate returns a true} ``` componentDidUpdate() { console.log('Component re-rendered.'); } render() { return

{this.props.value}

} }; ```
738
How can you use inline styling in React as opposed to HTML? What two things do we need to remember about how to write it?
you need to make it an object and make it JSX so it will look like it is in double objects and any key or property names that usually comes with a - in html will be written in camelCase in JSX ``` class Colorful extends React.Component { render() { return (
Big Red
<=== example ); } ```
739
If we have a lot of styling rules that we want to add in inline styling in react, how do we do so without writing them out individually?
store it in a keyword and apply it inline instead of writing. ``` const styles = { color: 'purple', fontSize: 40, border: '2px solid purple' } ```
Style Me!
<== applied stylings
740
where and how can you write regular javascript within a React component?
You can also write JavaScript directly in your render methods, before the return statement, without inserting it inside of curly braces. This is because it is not yet within the JSX code. When you want to use a variable later in the JSX code inside the return statement, you place the variable name inside curly braces.
741
How can you create an if/else statement inside of a render statement in a react component?
``` class MyComponent extends React.Component { constructor(props) { super(props); this.state = { display: true } this.toggleDisplay = this.toggleDisplay.bind(this); } toggleDisplay() { this.setState((state) => ({ display: !state.display })); } render() { // change code below this line if(this.state.display == true){ return (
Toggle Display

Displayed!

``` ``` );} else{ return (
Toggle Display
``` ) } } };
742
How can we use the && conditional and how can we use it to make our if/else statements more concise? Can we chain them?
Usually && means AND. but really what it means is if the first condition is true, return the second part of the code. so you can use it to say, if this is true...return this... and if its not true then the whole thing returns false. {this.state.display == true &&

Displayed!

} we can also chain these together to add multiple conditions if this...and that... and that....and that....and that...and that...and that is true return this.....example psuedocode
743
When we need to use an IF/ELSE statement inside of the return statement of a react component, what should we use?
We should use a ternary operator or && logic we can chain these together. ``` this.state.userAge === '' ? buttonOne : this.state.userAge >= 18 ? buttonTwo : buttonThree } ```
744
Can you use ternary conditionals to run different code based on the value of a prop that has been passed down to a Child Component in react?
yes you can you can do something like ``` return (

{ this.props.fiftyFifty ? 'You Win!': 'You lose!' }

``` this would say if props = true return you win if it is false return you lose to the DOM you can set up code that will either make the prop 50/50 either true or false before it passes it to the child component and then the component will render a particular type of code depending.
745
How can you set up a random expression that will return true or false with a 50/50 chance of being either?
Math.random( ) >= .5 ? true : false you can store this in a variable name and half the time it will randomly choose true or false. And then from here you can apply the variable name to anything you want along with the true/false variable.
746
How can we set up css rules to applied based on Component State?
set up two style objects with different variable names then set up some logic that will choose which one to apply based off state. This particular state will apply one style if the length is less than 15 regStyle = { border: 3px solid black } dangerStyle = { border: 3px solid red } style= {this.state.input.length > 16 ? dangerStyle : regStyle} ;
747
How can we use .map( ) to render elements within a state Array?
You can initialize a value as being an empty array in the state object - as we update our state we can add these updates to the array.... then in our render( ) we can map through the array and send them to the DOM (or do anything else we want to do with them) let items = this.state.arraylist.map(item=>
  • {item}
  • ) then in the return statement we can return it to the DOM return
      {items}
    748
    When we have react siblings that are the of the same element or items of an array what attribute do we need to make sure that we have on the element tag?
    We need to make sure that we have a key attribute. its a best practice to use a unique name key attribute, but an index can also be used as well. the keys need to be unique in comparison to the other items in the array or other siblings - it doesnt need to be unique globally through the program. ``` const renderFrameworks = frontEndFrameworks.map(item => { return
  • {item}
  • ``` this goes through an array and adds a li tag to each item and then it adds a key item with the same name as the text inside the list item. BUt every item will have different text that will also match its own key but will not match any other items on the list
    749
    When trying to use an array method like map( ) or filter( ) to render array items to the DOM, if the code breaks and doesnt work the way it should what should i check?
    Make sure that the items are not an object. Sometimes when mapping through an array of objects we forget to go to the deeper level of dot notation to access the information that we want. ``` const usersOnline = this.state.users.filter(item => iitem.online == true); // const renderOnline = usersOnline.map((item) =>
  • {item.username}
  • ); ``` here the items are objects so simply trying to use
  • {item}
  • wont work. You need to use username to go deeper into the object and access the proper data to the DOM
    750
    What does the renderToString( ) react method do? and how do we use it?
    This is a way to render your react app on a server as opposed to on the client side. ReactDOMServer.renderToString()
    751
    What are two real world examples of why you would want to render your react app on the server as opposed to the client?
    There are two key reasons why rendering on the server may be used in a real world app. First, without doing this, your React apps would consist of a relatively empty HTML file and a large bundle of JavaScript when it's initially loaded to the browser. This may not be ideal for search engines that are trying to index the content of your pages so people can find you. If you render the initial HTML markup on the server and send this to the client, the initial page load contains all of the page's markup which can be crawled by search engines. Second, this creates a faster initial page load experience because the rendered HTML is smaller than the JavaScript code of the entire app. React will still be able to recognize your app and manage it after the initial load.
    752
    When you make a container a grid and it has other elements in it, how are the items displayed or laid out?
    They are laid out as block elements, and those elements split the space of the container evenly in a row form. so 5 divs will look like this 1 2 3 4 5 if There was only 3 in the same container it would look like this 1
    753
    What two things do we need to remember about passing a function to a child component in react?
    the name of the function needs to be the key and the value when passing it with the child component name and then we need to use props in the child component button onClick={this.props.handleClick}
    754
    When you use max-width: 100% on a responsive image inside of a div what is the difference between normal width: 100%?
    the image will be responsive shrinking but will not grow past the size of the conatainer div original size. When you set it to regular width it will gorw and expand with the size of the div no matter how big or small
    755
    how do we write a positive/negative look behind?
    positive lookbehind ? < = negative lookbehind ? < ! **no spaces between**
    756
    What is a good mental model for look aheads and look behinds?
    these look to make sure that not only the pattern in your regex is there but also that the look ahead and look behind pattern is there too. the regex code = abc might be there.... but you want to search for abc thats followed by @gmail.com so you will use a lookahead to only find the abc followed by gmail and return just the abc not the gmail. this can be used if you wanted to find all the usernames of a gmail email list ``` abc@gmail.com 222@gmail.com 333@yahoo.com 676@hotmai.com abc@yahoo.com ``` if you search and match abc in normal regex youll get abc@gmail.com abc@yahoo.com but we only want the ones from gmail so if we use a look ahead for @gmail.com and abc as our regex it will match abc@gmail but only return the 'abc' part...which is the username
    757
    What is Redux?
    Redux is a state management framework that can be used with a number of different web technologies, including React.
    758
    What is the Redux Store?
    In Redux, there is a single state object that's responsible for the entire state of your application. the Redux store is the single source of truth when it comes to application state.
    759
    Anytime you're using Redux and you want to update any part of your App, where must you do it from?
    This also means that any time any piece of your app wants to update state, it must do so through the Redux store. The unidirectional data flow makes it easier to track state management in your app.
    760
    What data type is the Redux Store? What does it manage?
    The Redux store is an object which holds and manages application state.
    761
    How do we create the Redux Store?
    with the createStore( ) on the Redux Object.
    762
    What Argument is required by the the createStore( ) method?
    a Reducer Function let store = Redux.createStore(reducer) now we can use store to access different methods
    763
    How can we retrieve the current state of an app held in the Redux Store Object?
    store.getState( )
    764
    What is a Javascript Action Object? What info can it have? What info must it have?
    An action is simply a JavaScript object that contains information about an action event that has occurred. Sometimes a Redux action also carries some data. For example, the action carries a username after a user logs in. While the data is optional, actions must carry a type property that specifies the 'type' of action that occurred. ``` let action = { type : 'LOGIN' } ```
    765
    In Redux all state updates are triggered by what?
    In Redux, all state updates are triggered by dispatching actions. Think of Redux actions as messengers that deliver information about events happening in your app to the Redux store. The store then conducts the business of updating state based on the action that occurred.
    766
    How do you send an action to the Redux Store so it can update its state?
    by using an Action Creator. An action creator is simply a JavaScript function that returns an action. In other words, action creators create objects that represent action events. (action) ``` const action = { type: 'LOGIN' } ``` (action creator) ``` function actionCreater(){ return action } ```
    767
    What is a Dispatch method?
    It's what we use to dispatch actions to the Redux Store. Calling store.dispatch() and passing the value returned from an action creator sends an action back to the store. ``` const store = Redux.createStore( (state = {login: false}) => state ); ``` ``` const loginAction = () => { return { type: 'LOGIN' } }; ``` store.dispatch(loginAction()) store dispatch takes the function loginAction and dispatches back to the Redux Store
    768
    After an Action has been created and dispatched to the Redux Store, what does the Redux Store need to know and how do we tell it what to do?
    It needs to know how to respond to that Action and we tell it what to do with the Action by using a Reducer function Reducers in Redux are responsible for the state modifications that take place in response to actions
    769
    A Reducer Function takes what two arguments and what does it always return?
    it takes State and Action as arguments. it always returns a new State
    770
    Does a Reducer Function have any other responsibilities other than returning a new State?
    No, it does nothing other than this.
    771
    Should a Reducer Function return a copy of State or change State directly?
    A Reducer Function should never change State directly. It should return copy of State.
    772
    How can you handle Multiple Actions at once?
    With a switch statement. Every Action is an object that has to take a Type property. in the switch statement you pass action.type -- this will be checked against every switch entry. In the Case you match the value of the possible types in the block of that case you put an object with the desired value for example one actionCreator will pass the action object with type: login another action creator will pass an action object with type: logout another action creator will pass an action object with type: delete another action creator will pass an action object with type: post etc then in the switch you would have (action.type) ``` case logout: {authentication : false } case login: {authentication : true } case delete: {post : false } case post: {post : true } ``` this will all be in one switch statement hooked up to many different actionCreators so when one is fired, it will find the correct type... and then change and update the State. Actions that have different types but actually affect the same State. So both LogIn and LogOUT will update the State of Authentication And action.type delete and post will update the State of post
    773
    What do all Redux Switch Statements that update State need? And Why?
    A default case that returns the current state. Because once your app has multiple reducers they are all run anytime an action dispatch is made even when the action isn't related to that reducer. In such a case you want to make sure that you return the current State.
    774
    How should we assign Action Types in Redux?
    As const variables. Usually the way to do this is const variable names and then save a string with the same name to it. for example ``` const LOGIN = 'LOGIN' const LOGOUT = 'LOGOUT' ``` then when you use them in your switch statements and actionCreators and other places you should use the const variable name instead of the string themselves.
    775
    What is a Store Listener? How do you assign it?
    A Store Listener is a function that runs whenever an action is dispatched against the store. One simple use of this is to log a message every time an action is received and the store is updated. You do this by using store.subscribe( ) for example say you want to count how many times an action was sent to the store and updated State. then you can write a Store Listener to do this. let count = 0; ``` const update = () => { return count++ } ``` then you can pass the function in store.subscribe() like this store.subscribe(update)
    776
    What is the first principle of Redux?
    all app state is held in a single state object in the store.
    777
    When the state of your app begins to grow more complex, its unreasonable to expect to have one switch statement to handle all the states from all the different actions. How do we handle this while keeping the first principal of Redux intact?
    You define multiple reducers to handle different pieces of your application's state, then compose these reducers together into one root reducer. The root reducer is then passed into the Redux createStore() method. We combine multiple reducers using combineReducers( )
    778
    How does the method combineReducers( ) work?
    This method accepts an object as an argument in which you define properties which associate keys to specific reducer functions. The name you give to the keys will be used by Redux as the name for the associated piece of state. const rootReducer = Redux.combineReducers({ auth: authenticationReducer, notes: notesReducer }); each of these values would be a reducer functions with switch statements in them handeling the possibilies of state. saved intoan object and then passed into createStore( ) const store = Redux.createStore(rootReducer); now this store will have access to all the different possibilities of State.
    779
    What do Actions usually generate from ? And tend to carry what with them?
    From user interaction and carry some data with them Redux often needs to know about this data.
    780
    If you want to pass in some Data other than type along with Action Dispatch how do you do so?
    Add a parameter for an argument to be passed in the action creator. place a key/value pair with the parameter as the value ``` const addNoteText = (note) => { return { type: ADD_NOTE, text: note } }; ``` in the reducer's switch statement, when the case action type is matched return the value of the key value pair with dot notation ``` const notesReducer = (state = 'Initial State', action) => { switch(action.type) { case ADD_NOTE : return action.text default: return state; } }; ``` then dispatch the reducer to the store with the parameter filled store.dispatch(addNoteText('Hello!'));
    781
    What does Asynchronous Functions/Programming mean?
    this basically means when your code stops running because its waiting to retrieve data before it can continue. like an API call, this is asynchronous ---- dealing with how to handle this so it isn't inconvenience to the user is asynchronous programming.
    782
    What is the name of the MiddleWare that Redux provides to handle its asynchronous actions?
    Redux Thunk MiddleWare
    783
    How do you include Redux Thunk MiddleWare in your App?
    You pass it as an Argument to Redux.applyMiddleware( ) Redux.applyMiddleware(ReduxThunk.default)
    784
    Where do we place the | Redux.applyMiddleware(ReduxThunk.default) statement?
    As the second parameter to createStore( ) const store = Redux.createStore( asyncDataReducer, Redux.applyMiddleware(ReduxThunk.default) );
    785
    How do you create an Asynchronous Action?
    to create an asynchronous action, you return a function in the action creator that takes dispatch as an argument. Within this function, you can dispatch actions and perform asynchronous requests. ``` const handleAsync = () => { return function(dispatch) { dispatch(requestingData()); setTimeout(function() { let data = { users: ['Jeff', 'William', 'Alice'] } dispatch(receivedData(data)); }, 2500); } }; ```
    786
    What should we do inside of the Asynchronous Dispatch Function before initiating any Asynchronous behavior and why?
    It's common to dispatch an action before initiating any asynchronous behavior so that your application state knows that some data is being requested (this state could display a loading icon, for instance) ``` const handleAsync = () => { return function(dispatch) { dispatch(requestingData()); setTimeout(function() { let data = { users: ['Jeff', 'William', 'Alice'] } ``` set time out is a mock API call the dispatch function is the action telling that its requesting data
    787
    Inside of your Dispatch Function after you have received the data made by the Data Request Action (API call) what do we do?
    We Dispatch another Action which carries the data as a Payload along with information that the action is completed. ``` const handleAsync = () => { return function(dispatch) { dispatch(requestingData()); setTimeout(function() { let data = { users: ['Jeff', 'William', 'Alice'] } dispatch(receivedData(data)); }, 2500); } }; ``` set time out is a mock API call dipatch(rec) is an action with data being passed as the received information.
    788
    After you pass Dispatch as an Argument in a function handling Asynchronous behavior in Redux, how do you apply it to the actions to dispatch it?
    you call it like a function dispatch(requestingData()); dispatch(receivedData(data));
    789
    What is an example of a Redux App used to make a counter of State?
    ``` const INCREMENT = 'INCREMENT'; const DECREMENT = 'DECREMENT'; ``` ``` const counterReducer = (state = 0, action) => { switch (action.type){ case INCREMENT : return state + 1 case DECREMENT : return state - 1 default: return state } }; ``` ``` const incAction = () => { return { type: INCREMENT, } }; ``` ``` const decAction = () => { return { type: DECREMENT } }; ``` const store = Redux.createStore(counterReducer);
    790
    We never want to mutate a state directly in Redux we want to make a copy of it and then mutate it. How can we do this and what is an example of it?
    We can do this with regular javascript inside of a reducer function by copying the state before the Switch Statement. ``` const todos = [ 'Go to the store', 'Clean the house', 'Cook dinner', 'Learn to code', ]; ``` const immutableReducer = (state = todos, action) => { let newlist = [...todos]; notice that newlist is copied to the global variable of state and not to the state parameter. this is done before the switch statement. After the Switch Statement we modify the copy switch(action.type) { case ADD_TO_DO: newlist.push(action.todo) return newlist todo represents the data updating the todo array which is being returned as the new state
    791
    When passing extra data along with an action besides Type (like a message or something) does that extra information need to be in object form although the Action creator is returning an object?
    No the variable name can represent any form of data ``` // an example todo argument would be 'Learn React', const addToDo = (todo) => { return { type: ADD_TO_DO, todo } } ``` Here todo represents a string 'learn react'. It isnt in the usual data structure of an object. But it can be later accessed in the Reducer function as if it were ``` switch(action.type) { case ADD_TO_DO: newlist.push(action.todo) return newlist default: return state; } }; ``` notice the action.todo being pushed to the newlist variable this will push the string being represented in the action object into the array
    792
    How can we remove an item from a State array inside of a Reducer function if provided the index, without affecting or mutating State?
    ``` const immutableReducer = (state = [0,1,2,3,4,5], action) => { switch(action.type) { case 'REMOVE_ITEM': let a = state.slice(0, action.index); let b = state.slice(action.index + 1); return a.concat(b) default: return state; } }; ``` ``` const removeItem = (index) => { // console.log(index) return { type: 'REMOVE_ITEM', index } } ``` ``` removeItem(5) const store = Redux.createStore(immutableReducer); ```
    793
    What does Object.assign( ) do?
    It copies and merges objects
    794
    How can we use Object.assign( ) to copy an object?
    let newObject = Object.assign( { }, obj 1) This will copy all the properties and values in obj1 into the empty array
    795
    Can you copy more than one object into an empty object by using Object.assign( )? How?
    Just add more objects as arguments let newObject = Object.assign( { }, obj1, obj2, obj3) this will add all of the properties of the three objects into the empty object.
    796
    What happens if you use Object.assign( ) to copy or merge objects and some of the objects have the same properties?
    Matching properties are overwritten by the latest object that is added. This is a way that you can update Objects in Redux when the object represents state.
    797
    Although React Components can manage their own state locally, with a complex app it is generally better to keep the state where?
    In a single location with Redux
    798
    What is a React-Redux package? Why is it needed?
    Redux isn't designed to work with React outside of the box so you need to use this package that allows you pass State and Dispatch to React Components as Props
    799
    How do we make text entered by a User to update State in React? the three things you need are...
    1. place in state to be updated 2. an element for a user to text in 3. element set with value={this.state.input} 4. set state in function set to {input = {event.target.value} with an event parameter passed in
    800
    Besides the Constructor method inside of class Component, where else can you bind a Function that changes State to the keyword 'This'?
    You can bind it directly on the element that you are using to change state input ={this.handleChange.bind(this)}
    801
    How can you empty an input box or any text of some sort When changing state?
    apply an empty string to the element as its value. this is a better way when dealing with State instead of using $('input').val(' '). this.setState({ input: '' }) using better
    802
    When adding items to an array in State, how should we do it besides using the push method?
    we should use the spread operator to concatenate them into a new array. messages : [...this.state.messages, this.state.input]
    803
    What is the Provider tag and how is it used and what is it used for?
    The Provider is a wrapper component from React Redux that wraps your React app. This wrapper then allows you to access the Redux store and dispatch functions throughout your component tree. ``` class AppWrapper extends React.Component { render() { return ( ``` ); }
    804
    What two things do you need to make sure you provide with the Provider tags?
    You need to add Store as a prop and you need to place the React Component you want to connect with Redux inside the wrapper Provider tags.
    805
    How do we create the Provider tag?
    const Provider = ReactRedux.Provider; then you can use it as a tag
    806
    What does mapStateToProps( ) do? What is the purpose ? How do we construct it?
    You use this to create a function that specifies to you React Component which State it has access to. ``` let mapStateToProps = (state) => { return { messages: state} } ```
    807
    What parameter does mapStateToProps( ) take?
    state.
    808
    What is mapDispatchToProps( )? What does it do?
    The mapDispatchToProps() function is used to provide specific action creators to your React components so they can dispatch actions against the Redux store.
    809
    How do we construct mapDispatchToProps( )? What are the 6 steps?
    1. mapDispatchToProps( ) takes dipatch as param 2. returns an object with one property 3. property value is a function with param 4. function calls dispatch 5. in param of dispatch it takes action creator and its param 6. param of action creator matches property function param ``` const mapDispatchToProps = (dispatch) => { return { submitNewMessage: (message)=>{ dispatch(addMessage(message)) } } } ```
    810
    After you have written mapStateToProps( ) and the mapDispatchToPage( ) what then can you do?
    You can use them to map State and dispatch to the props of one of your React Components
    811
    How do you create the Connect method and what does it do?
    const connect = ReactRedux.connect connects React to Redux
    812
    How many arguments does the Connect method take? Are they required?
    This method takes two optional arguments, mapStateToProps() and mapDispatchToProps(). They are optional because you may have a component that only needs access to state but doesn't need to dispatch any actions, or vice versa.
    813
    What is the syntax of calling Connect?
    To use this method, pass in the functions as arguments, and immediately call the result with your component. This syntax is a little unusual and looks like: connect(mapStateToProps, mapDispatchToProps)(MyComponent)
    814
    If you want to omit one of the parameters in Connect, how do you do so?
    You replace the omitted function with 'null'
    815
    What is a Presentational Function?
    . This term generally refers to React components that are not directly connected to Redux. They are simply responsible for the presentation of UI and do this as a function of the props they receive
    816
    What is a Container Function? | How do you contruct it?
    By contrast, container components are connected to Redux. These are typically responsible for dispatching actions to the store and often pass store state to child components as props. const Container = connect(mapStateToProps , mapDispatchToProps)(Presentational)
    817
    Once Redux is connected to you React Component, what do you need to do next?
    Extract the state management out of the Presentational component and into Redux.
    818
    What are the three things that need to be done to Extract Local State into Redux?
    1. remove local state to be placed in Redux 2. replace function that changes state locally and apply Redux Function that changes state through props ex. this.props.submitNewMessage(this.state.input) 3. Produce state in the render method through Props instead of local State {this.props.messages.map( (message, idx) => { return (
  • {message}
  • 819
    If we use Redux to manage State, do we need to use state locally in a React Component at all?
    Yes we still need it, not all things that we put into state will need to be handled by Redux. For example a React Component might have an local state that tracks the input in a text box. Then that text is to be sent somewhere and done something with, like added to a list or something. The input of the text might stay local and be handled local... but the adding of the text to a list will be done with Redux.
    820
    how to play audio file on button click?
    set audio file up so it works set button up add id on audio element save audio into variable by using getElementById create onClick function for button in the function declare variablename.play( )
    821
    how do we deal with the chain affect of divs when styling | an app that is rendered by a react component?
    html, body, app(component id), addDiv (id of the manditory div used in react){ height: 100% }
    822
    onKeyPress and other Keyboard events in React, dont work the same way that onClick does. How do we get 'Key Events' to work in a React Component then?
    We use add EventListener like this : componentWillMount(){ document.addEventListener("keydown", this.handlekeypress.bind(this)); } then create a function like : handlekeypress(){ console.log('working') } then pass it down to the element/child component return
    } then...if you pass it to a child compoenent, us props to apply it to the element. onKeyDown={this.props.handlekeypress}
    823
    What does key.code do?
    key is just an arbitrary parameter name that is passed in a function, but adding .code on it during a keyboard event like 'keypress' or 'keydown' gives the code for the key that is pressed on the keyboard by the user.
    824
    How do we add an event listener?
    document.addEventListener(firing event, function to happen)
    825
    Does a React Child Component need to have a constructor or super if its purpose is just to show the design and visual component of the code?
    No, you just need the render and return statements. | along with extends React.Component
    826
    How do i use event.target to get the id of an | element in React?
    let check = event.target.id
    827
    ``` How do i use event.target to get the class of an element in React? ```
    let check = event.target.className
    828
    How do i use event.target to get the inner | content of an element in React?
    by using jquery let check = $(event.target).text();
    829
    How do we disable a function or a prop on an element?
    by using Jquery and the disable method. to disable $(element/.class/#id).prop('disabled', true/false) this will disable or enable it. ** MAKE SURE YOU WRITE 'DISABLED' with a D and not 'Disable'. It wont work otherwise
    830
    if you want to turn a string data type into a number data type, how do you do so?
    save number into variable and place it inside Number() then save that inside a variable check = "32" Number(check) let result = Number(check) result = 32
    831
    ``` When you use a constructor inside of a class what must you also have when creating a state? ```
    The super( ) method.
    832
    When making a state with constructor what keyword do you need when setting the object?
    this.state = { }
    833
    ``` When making state without a constructor inside of a class function what dont you need? ```
    The keyword this. state = { }
    834
    How do use Regex to validate US telephone numbers in all their forms including optional country code and mandatory area code?
    let regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/
    835
    How do you access object values and keys in a For/In loop?
    You have to use Bracket Notation to access value because youre creating a new variable name and variable names have to be accessed with Bracket Notation.
    836
    How do we change floats into integers?
    save floats to variable, then save Math.floor(variable) to another variable, it will be saved as integers. ``` example let divide = leftover / currency[coinAmount] let results = Math.floor(divide) console.log(results) ```
    837
    How do we set up the ready function in Jquery?
    $(document).ready(function(){ add code you want ran when you first load page here or name of function (more than likely this one) })
    838
    How do you call another jquery function inside another jquery function?
    just call the name of the function like normal function OtherJqueryFunction(){ createdfunctionName() }
    839
    How do you change the color of an elements text in jquery?
    .css('color', 'red')
    840
    How do you add a function on an elements click in jquery?
    .on('click', function(){ type code here }
    841
    How should you write your functions in jquery as far as handling funtionality?
    every function should handle a specific function of the app. Seperation of concerns
    842
    What is the syntax for Fetching an API call?
    fetch("url").then(response => response.json()).then(data => console.log(data)) this logs it to the console and then you should add a function afterwards to do something with it, using data as a parameter.
    843
    what is animation delay ?
    sets how long before an animation runs so it doesnt run right away
    844
    what does setInterval do?
    it runs a function over an over again after a certain amount of time which is set by user
    845
    how do you stop the setInterval method?
    with a clearInterval method
    846
    How to make text center horizontally and vertically?
    text-align: center; | line-height: (set value equal to height of div)
    847
    z-index only works on what type of elements?
    positioned elements
    848
    how do you apply psudeo classes like :hover?
    we apply it to the very end of the class or id name, with no spaces. .class-name:hover { }
    849
    if we want to add hover to multiple elements how do we do it?
    we list them all and seperate them with commas .class-name:hover, .other-class-name:hover { }
    850
    if we use psuedo classes on one element, does that mean that every element chosen as a selector for a rule set have to also have the same psuedo class?
    ``` No it doesnt, but the ones that dont have the pseudo class will always show that styling rule. ``` .class-name:hover, #id-name { border: blue; } id-name will have a blue border always class-name will only have a blue border when its hovered over
    851
    What does D3 stand for?
    Data Driven Documents
    852
    What is D3?
    D3 is a JavaScript library to create dynamic and interactive data visualizations in the browser. It's built to work with common web standards, namely HTML, CSS, and Scalable Vector Graphics (SVG).
    853
    What is SVG?
    Scalable Vector Graphics
    854
    What is the select( ) method in D3? what is the syntax?
    The select() method selects one element from the document. It takes an argument for the name of the element you want and returns an HTML node for the first element in the document that matches the name. Here's an example: const anchor = d3.select("a"); The above example finds the first anchor tag on the page and saves an HTML node for it in the variable anchor. You can use the selection with other methods. The "d3" part of the example is a reference to the D3 object, which is how you access D3 methods.
    855
    What is the append( ) method in D3?
    The append() method takes an argument for the element you want to add to the document. It appends an HTML node to a selected item, and returns a handle to that node. d3.select("ul") .append("li") this appends a list item to a selected ul element
    856
    What two things can a text( ) method do in D3?
    The text() method either sets the text of the selected node, or gets the current text. To set the value, you pass a string as an argument inside the parentheses of the method. d3.select("ul") .append("li") .text("Very important item"); this is an example of a text method setting a string inside of a list item thats appended to a selected ul element
    857
    Can you chain methods in D3?
    yes you can d3.select("ul") .append("li") .text("Very important item");
    858
    What is selectAll( ) method in D3?
    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");
    859
    Does selectAll support chaining?
    yes it does
    860
    When you have a set of data ( like an array of numbers) you can use D3 to do what?
    Display it on the page
    861
    When using D3 methods to display data on the page, what is the first step?
    Making D3 aware of the Data
    862
    How do you make D3 aware of data so it can put it on the page?
    you first select an element or elements and then use the data method and passing the data which is saved in a variable as an argument. ``` const dataset = ["a", "b", "c"]; d3.select("ul").selectAll("li") .data(dataset) ```
    863
    What does the enter( ) method do in D3?
    When enter() is combined with the data() method, it looks at the selected elements from the page and compares them to the number of data items in the set. If there are fewer elements than data items, it creates the missing elements. ``` const dataset = ["a", "b", "c"]; d3.select("ul").selectAll("li") .data(dataset) .enter() .append("li") .text("New item"); ``` 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".
    864
    What can text( ) take as an argument in D3?
    it can take a string or an function as an argument .text((item) => { return item + ' USD' });
    865
    when a function with a parameter passed as an argument in the text( ) method in D3 and bound to array as a data set, what does that parameter represent?
    the items inside the array. it works the same way as a parameter in maps( ). const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9]; ``` d3.select("body").selectAll("h2") .data(dataset) .enter() .append("h2") // Add your code below this line ``` .text((item) => { return item + ' USD' }); item equals the array items ``` 12 USD 31 USD 22 USD 17 USD 25 USD 18 USD 29 USD 14 USD 9 USD ```
    866
    What does the style( ) method do in D3?
    It allows you to add inline styles to an element
    867
    How are styles added in D3 style tag?
    with comma separated key value pairs. selection.style("color","blue");
    868
    How can we use conditional logic to add certain visual aspects to an element if condition is met in D3?
    We use a call back function with conditional logic as the second argument of the style( ) method ``` .style("color", (d) => { if (d < 20){ return 'red' } else { return 'green' } }) ```
    869
    How do you add a class to an element using D3?
    with the attr( ) method the first paramter will be class and the second param the name of that class selection.attr("class", "container");
    870
    How can we use the dataset of a numbers array in D3 to dynamically set the height of div elements like a chart?
    ``` const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9]; d3.select("body").selectAll("div") .data(dataset) .enter() .append("div") .attr("class", "bar") .style('height', d => `${d}px`) ```
    871
    What does "Scalable" mean in SVG?
    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.
    872
    What is SVG commonly used for?
    SVG is used to make common geometric shapes.
    873
    Where's must the SVG shapes go?
    In the HTML svg tag d3.select("body") .append('svg')
    874
    CSS can be used to make scaleable styles when using relative units of measurements like 'vh', 'vw' or "%'s", but using SVG for data visualizations is....
    More flexible
    875
    Do we need using 'unit measurements' for attr( ) when setting things like height or width? What ratio should we set height and width?
    When using attr( ) 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. ``` const w = 500; const h = 100; ``` const svg = d3.select("body") .append('svg') .attr('width', w ) .attr('height', h)
    876
    What are the basic 5 steps of creating an SVG shape?
    create an SVG space for the shape define its height and width create an SVG shape that goes inside the space define its height and width define where it goes on the x axis of space define where it goes on the y axis of space ``` d3.select("body") .append("svg") .attr("width", w) .attr("height", h) .append("rect") .attr('width', 25) .attr('height', 100) .attr('x', 0) .attr('y', 0) ```
    877
    How can we add a SVG shape for every item in a dataset?
    first create a svg space inside an element save that div in a variable name then attach the data set and and enter and append to that vairable name along with the same const svg = d3.select('body) .append('svg') .attr("width", w) .attr("height", h); svg.selectAll("rect") .data(dataset) .enter() .append("rect")
    878
    How do you set the coordinates for multiple shapes inside of an SVG space? How many parameters do we need?
    With a call back function that dynamically sets the 'x' and 'y' property with attr( ) method. ``` svg.selectAll("rect") .data(dataset) .enter() .append("rect") .attr("x", (d, i) => { return i * 30 }) ``` this will make each data item produce a rectangle that starts 30px to the right every iteration we need two, d represents the item of the array. i equals the value that will set the x or y axis 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.
    879
    Do we need a for loop or a foreach( ) when using the data( ) in SVG?
    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.
    880
    When we set SVG shapes with various heights, it can appear which way when only setting the x axis?
    it can appear upside down because the default is 0 , 0 which places it in the left hand upper corner
    881
    How can we reverse the appearance of upside down SVG shapes by adjusting the y property?
    y = heightOfSVG - heightOfBar would place the bars right-side-up. so... h = 100 (height of svg area) 3 * d = (height of bar) so turning the bars upside down by setting the y property by attr("y", (d, i) => h - 3 * d)
    882
    SVG shapes can be colored with what property in attr( ) ?
    the fill property attr('fill','red')
    883
    How can you add pseudo elements/classes or css without using multiple styles or attr( ) methods in D3?
    You can make a rule set in CSS, and apply the class with a single attr( )
    884
    What are tooltips?
    A tooltip shows more information about an item on a page when the user hovers over that item.
    885
    How can we use tooltips in SVG?
    You can use the title element and add it to each element you want to add it to like a 'rect' element, and then call a text method with a call back function .append('rect') .text((d) => d) this d will go with the dataset and iterate through it and represent each item and take that value and return it as text
    886
    What are the three main attributes of the circle shape in SVG?
    cx, cy and radius. cx and cy set the location of the circle. here the center of the circle will be r will tell us the radius, the size of the actual circle
    887
    Are the y and cy attributes measured from the top or the bottom of the SVG area?
    The top
    888
    Can cy, cx and r all be set dynamically?
    yes they all can take the a callback functions
    889
    What happens to all methods chained after dataset in D3?
    all methods chained after data(dataset) run once per item in dataset
    890
    What does the d parameter represent in D3 callback functions? How can we access specific points?
    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.
    891
    How can you make a right side up bar chart with the height representing numbers in an array with labels and toolkits on the hover function?
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9]; ``` const w = 500; const h = 100; ``` const svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); ``` svg.selectAll("rect") .data(dataset) .enter() .append("rect") .attr("x", (d, i) => i * 30) .attr("y", (d, i) => h - 3 * d) .attr("width", 25) .attr("height", (d, i) => d * 3) .attr("fill", "navy") .attr("class", "bar") .append('title') .text((d) => d) ``` ``` svg.selectAll("text") .data(dataset) .enter() .append("text") .text((d) => d) .attr("x", (d, i) => i * 30) .attr("y", (d, i) => h - (d * 3 + 3)) ```
    892
    How to build a scatter plot in SVG with D3, that represents data points?
    ``` 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; ``` const svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); ``` svg.selectAll("circle") .data(dataset) .enter() .append("circle") .attr("cx", (d, i) => d[0]) .attr("cy", (d, i) => h - d[1]) .attr("r", 5); ``` ``` svg.selectAll("text") .data(dataset) .enter() .append("text") // Add your code below this line ``` .attr("x", (d) => d[0] + 5) .attr("y", (d) => h - d[1]) .text((d) => (d[0] + ", " + d[1]))
    893
    What method do we use to make a linearScale? And how would you save it in a variable?
    scaleLinear( ) const scale = d3.scaleLinear()
    894
    What are scales in SVG and why are they used?
    When using charts or plot points in SVG areas, sometimes youll have data that is outside of the designated space for that SVG space, so you use a scale or different types of scales to specify how you want the data plotted visually. You rarely plot data as it - most of the time you want to specify how to scale it inside the height and width inside your space
    895
    What is the input information for a scale and what is it called?
    It is called the 'Domain' and say if a dataset had a range of numbers from 50 - 480, This would be the domain domain( )
    896
    What is the output information for a scale and what is it called?
    It is called the 'Range' and it is the points along the x axis of your SVG space that you want to stay in between. Like 10 - 500 range( )
    897
    What does domain( ) and range( ) take as arguments?
    It takes an array of at at least two elements scale. domain([50, 480]) scale. range([10, 500])
    898
    How we find the highest or lowest number in an array to help us with setting the domain( ) or range( ) of a scale?
    You can use .min or .max const exampleData = [34, 234, 73, 90, 6, 52]; d3. min(exampleData) // Returns 6 d3. max(exampleData) // Returns 234
    899
    If a dataset has nested arrays we can just use .min and .max on it because it will not return accurate data, what can we do?
    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 ```
    900
    How can you add padding to the scale to make sure the data points dont brush up against the sides?
    Add a padding varable saved to a number value and use those in teh equations for range( ) and domain( ) ``` 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]); ```
    901
    How do you add the scale parameters to the actual data points before plotting?
    make them the second argument of the x and y parameters of the attr( ) method -- or the cy cx parmeters for circles. This sets up the functions xscale and yscale ``` const xScale = d3.scaleLinear() .domain([0, d3.max(dataset, (d) => d[0])]) .range([padding, w - padding]); ``` ``` const yScale = d3.scaleLinear() .domain([0, d3.max(dataset, (d) => d[1])]) .range([h - padding, padding]); ``` Then you pass it through like so .attr("cx", (d) => xScale(d[0])) .attr("cy", (d) => yScale(d[1]))
    902
    How do we create an x or yaxis of our chart that gives up information about what the data means?
    we first create a variable for it xAxis =d3.axisBottom(xScale) or yAxis = d3.axisLeft(yScale) const xAxis = d3.axisBottom(xScale); const yAxis = d3.axisLeft(yScale); svg.append("g") .attr("transform", "translate(0," + (h - padding) + ")") .call(xAxis); svg.append("g") .attr("transform", "translate(" + padding + ",0)") .call(yAxis)