Code 201 Class 3 Reading Notes
Lists
- There are three types of HTML lists: ordered, unordered, and definition
- Ordered lists use numbers.
- Unordered lists use bullets.
- Definition lists are used to define terminology.
- Lists can be nested inside one another.
Example of Definition
<dl>
<dt>definition</dt>
<dd>a statement of the exact meaning of a word, especially in a dictionary</dd>
</dl>
Boxes
Border, Margin & Padding
Every box has three available properties that can be adjusted to control it’s appearance.
Every box has a border (even if it is not visible or is specified to be 0 pixels wide). The border seperates the edge of one box from another.
Margins sit outside the edge of the border. You can set the width of a margin to create a gap between the borders of two adjacent boxes.
Padding is the space between the broder of a box and any content conatained within it. Adding padding can increase the readiability of its contents.
Rounded Corners
p {
border: 5px solid #ee3e80;
padding: 20px;
width: 275px;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
}
- CSS treats each HTML element as if it has its own box.
- It is possible to hide elemenets using the display and visibility properties.
Arrays
An array is a special type of variable. It doesn’t just store one value; it stores a list of values.
var colors;
colors = ['white', 'black', 'custom'];
IF…Else Statements
The if…else statement checks a condition. If it resolves to true the first code block is executed. If the condition resolves to false the second code block is run instead.
if (score >= pass) {
msg = 'Congratulations, you passed!';
} else {
msg = 'Have another go!';
}
Loops
Loops check a condition. If it returns true, a code blaock will run. Then the condition will be checked again and if it still returns true, the code block will run again. It repeats until the condition returns false. There are three common types of loops.
FOR
If you need to run code a specific number of times, use for loop. (It is the most common loop.) In a for loop, the condition is usually a counter which is used to tell how many times the loop should run.
WHILE
If you do not know how many times the code should run, you can use a while loop. Here the condition can be something other than a counter, and the code will contiunue to loop for as long as the condition is true.
DO WHILE
The do…while loop is very similar to the while loop, but has one key difference: it will always run the statements inside the curly braces at least once, even if the condition evaluates to false.
- Logical operators allow you to combine more than one set of comparison operators.
- Data types can be coerced from one type to another.