An online markdown blog and knowledge repository.
HTML Chapter 2: Text HTML Chapter 10: Intro to CSS JS Chapter 2: Basic Instructions JS Chapter 4: Decision Loops (part 1)
Focus of this chapter are structural markup and semantic markup.
Headings:
<h1>
through <h6>
Paragraphs:
<p></p>
Bold and Italic:
<b></b>
<i></i>
Superscript and Subscript:
<sup></sup>
9th
or in math when denoting 'to the power of'<sub></sub>
White Space:
Line Breaks and Horizontal Rule:
These are 'empty elements' and require the closing tag character /
within these single-tag elements.
<br />
<hr />
These add information to a web page, and are used by screen readers and other assistive tools.
Strong and Emphasis:
<strong></strong>
<em></em>
Quotations:
<blockquote></blockquote>
<q></q>
"
by browsers but IE does notBoth blockquote and q include an optional cite
attribute that should be configured with the URL of the source of the quotation
Abbreviations and Acronyms:
<abbr></abbr>
Citrations and Definitions:
<cite></cite>
<dfn></dfn>
Author Details
<address></address>
Changes to Content
<ins></ins>
<del></del>
<s>
CSS is like a set of rules the browser follows to layout, colors, size and shape of the content.
CSS terminology:
text/css
Web sites can reference multiple external stylesheets.
Pages can share the same style sheet.
Single place to edit style information for the entire site.
Inline CSS rules can be eliminated (or minimized) thus cleaning-up the code.
Is a best practice.
Set CSS style rules for the current page.
Usually stored in the <head>
element, and/or in-line with html elements.
Single-page websites might use internal css to keep everything together.
Apply a few rules to a page with an external CSS ref, for specific situations (not a best practice).
For code examples in a learning textbook like Duckett's HTML and CSS boook.
Several portions of this were lifted from [Duckett, pg.238]
<h1>
etc.elClass
#elId
li>a {}
p a {}
h1+p {}
h1~p {}
CSS Rules have an order of precedence:
!important
indicates the rule is higher precendence than other rules that apply to the same elementSeveral portions of this were lifted from [Duckett, pg240]
CSS Definitions and releases overview:
Meanwhile, there are many browser makes and models, and releases.
Browser Quirks aka CSS bugs: A CSS property that displays in an unexpected way.
Online CSS Validation Tools Reference [Duckett, pg.242]
CSS Bug Sites Reference [Duckett, pg.242]
Individual instructions are called Statements.
A code block is contained between curly braces {
and }
Code blocks contain one or more Statements.
Code blocks can contain other code blocks.
JavaScript is CaSe SeNsItIvE
Statements are separated by a new line, and should end with a semicolon
There are two types of comments: Multi-line and Single-line.
Use comments to document the code, or to stop commented code statements from executing for testing.
Variables store data in memory.
The JavaScript interpreter executes code statements one at a time, in order, and variables allow the interpreter to store values for future code statements to recall the variable to obtain the value.
Data stored within a variable can be changed.
There are two steps to storing data in a variable (memory):
Declare the variable: var age;
Assign a value to them: thingy = 11;
Note: A variable that is declared but not assigned has a type of 'undefined'.
Some common data types are:
Additional types:
Numeric: Do not use quotations, just a raw integer or decimal number, followed by a semicolon.
String: Use single quotes '
or "
to encapsulate the string data, but do not mix them.
To include a quote insie of a string, encapsulate the entire string value with the other type of quote mark. Example using single and double quotes:
var message = '<p class="intro">Welcome to my website!</p>';
Example using the escape character \
:
<p class="post">My car has a name: \"Scooby\"</p>
Assign a variable the keywords 'true' or 'false'.
Do not use quotation marks for the keywords.
var switchIsOn = true;
Instead of taking two steps to declare a variable and assign it a value, both can be done in a single line:
var sales = 150000;
Multiply your efforts by declaring and assigning multiple variables on each line!
var sales = 150000, year = 2022;
Note: Assignment is not required when declaring multiple variables in a single statment.
Once a variable has been declared, the 'var' keyword is no longer necessary when assigning to the variable, or returning its stored value.
var stimpy = "cat";
stimpy = "cartoon character";
Varible names in JavaScript Can:
$
or _
; NOT a number-
nor .
Arrays store lists of variables.
Initialize arrays with the syntax var myArray = [ ];
Initialize and assign values to an array of integrals with var myArray = [ 1, 2, 3, 4, 5 ];
Alternately, use the array literal initialization: var myArray = new Array( 1, 2, 3, 4, 5);
Determine the number of items in an array with myArray.length;
Arrays are zero-based indexed storage types.
Arrays include an indexer:
var arrayItem = myArray[2];
myArray[2] = 100;
"An expression evaluated into a single value." [Duckett, pg.74]
There are two types of expressions: Simple assignment; Return a single value from two or more variables.
var name = 'Dave';
var sum = 2 * 3;
Expressions rely on operators (see next subsection).
The following symbols will perform mathematical operations on Number types:
+
-
*
/
++
--
%
The rules you learned about mathematical orders of operation are followed in JavaScript: PEMDAS.
There is only one, the concatenation operator: +
Use it to 'add' strings together!
var name = "Tom";
var action = "ran";
var place = "Madrid, Spain";
var sentence = name + " the 3rd grader " + action + " from his home in Paris to " + place + ", overnight!";
console.log(sentence);
The concatenation operator will bring together the string values on either side of it, so the previous code block when executed would return the following to the console: "Tom the 3rd grader ran from his home in Paris to Madrid, Spain, overnight!"
Comparison Operators and Logical Operators are covered in Chapter 4.
This chapter will cover the topics of evaluations, decisions, and loops.
JavaScript can be coded to make decisions based on current variables, user input, etc.
A flow chart is a great example of a decision tree, which could be used to help programmers write conditional statements.
In order to make a decision, code statements must:
Equal to ==
evaluates equality of values on each side of the operator, but not the types.
Not equal to !=
evaluates like Equal, but returns the opposite result.
Note: For this class, avoid using 'loosely equals' and 'loosely not equals' because it will evaluate different types as 'loosely equal' and that might not be intended behavior.
Strict equal to ===
evaluates the type and the value and returns true only if both conditions are true.
Strict not equal to !==
evaluates the opposite of Strict Equal To.
Note: Stick with Strict evaluators to check that the type is the same before evaluating if the values are the same.
Greater than >
evaluates true if the left-hand value is larger than the right-hand value.
Greater than or equal to >=
evaluates the same way >
and ==
do, and returns true if one or the other is true.
Less than <
evaluates true if the left-hand value is smaller than the right-hand value.
Less than or equal to <=
evaluates the same way <
and ==
do, and returns true if one or the other is true.
Enclosing brackets '(' and ')' are used to create a comparison operating statement.
Operands sit on either side of the comparison operatork, between the enclosing brackets.
(savingsAccount >= withdrawlAmount)
Expressions with operands can be used on either or both sides of the comparison operator within enclosing brackets to perform the comparison on the results of the expressions.
( (10 - 6) < (8 - 2))
AND: &&
If both expressions return true then the operator result is true.
OR: ||
If either expression returns true then the operator result is true.
Not: !
Inverts a Boolean value. If a conditioni returns 'true', !condition returns 'false'.
Both AND and OR are short-circuit evaluations: AND returns false as soon as a false if found; OR returns true as soon as a true is found.
The IF statement is used to check a condition and executes the following codeblock only if the condition returns 'true'.
IF statements can be followed by ELSE statements with another code block that executes when the IF conditioni returns 'false'.