Jon Rumsey

An online markdown blog and knowledge repository.


Project maintained by nojronatron Hosted on GitHub Pages — Theme by mattgraham

Notes from Duckett HTML and JS Books

HTML Chapter 2: Text HTML Chapter 10: Intro to CSS JS Chapter 2: Basic Instructions JS Chapter 4: Decision Loops (part 1)

HTML Book Chapter 2: Text

Focus of this chapter are structural markup and semantic markup.

Structural Markup

Headings:

Paragraphs:

Bold and Italic:

Superscript and Subscript:

White Space:

Line Breaks and Horizontal Rule:

These are 'empty elements' and require the closing tag character / within these single-tag elements.

Semantic Markup

These add information to a web page, and are used by screen readers and other assistive tools.

Strong and Emphasis:

Quotations:

Both blockquote and q include an optional cite attribute that should be configured with the URL of the source of the quotation

Abbreviations and Acronyms:

Citrations and Definitions:

Author Details

Changes to Content

HTML Book Chapter 10: Introducing CSS

CSS is like a set of rules the browser follows to layout, colors, size and shape of the content.
CSS terminology:

External 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.

Internal CSS

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.

Selectors

Several portions of this were lifted from [Duckett, pg.238]

How CSS Rules Cascade

CSS Rules have an order of precedence:

Inheritance

Several portions of this were lifted from [Duckett, pg240]

Different Versions of CSS and Browser Quirks

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]

JS Book Chapter 2: Basic JavaScript Instructions

Statements

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

Comments

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

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):

  1. The var keyword is used to define the variable name.
  2. The variable name is assigned a variable value using an assignment operator.

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'.

Data Types

Some common data types are:

Additional types:

Using Variables for Storage

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.

Strings and Quotes

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>

Store a Boolean

Assign a variable the keywords 'true' or 'false'.
Do not use quotation marks for the keywords.

var switchIsOn = true;

Creating Variables

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.

Changing the Value of a Variable

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";

Runes for Naming Variables

Varible names in JavaScript Can:

Arrays

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:

  1. Access the 3rd item in the array with the following syntax: var arrayItem = myArray[2];
  2. Assign the 3rd item in the array a new value: myArray[2] = 100;

Expressions and Operators

"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.

  1. Simple Assignment Expression: var name = 'Dave';
  2. Multi-value Single-return Expression: var sum = 2 * 3;

Expressions rely on operators (see next subsection).

Arithmetic Operators

The following symbols will perform mathematical operations on Number types:

The rules you learned about mathematical orders of operation are followed in JavaScript: PEMDAS.

String Operators

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!"

Additional Operators

Comparison Operators and Logical Operators are covered in Chapter 4.

JS Book Chapter 4: Decisions and Loops (up to switch statement)

This chapter will cover the topics of evaluations, decisions, and loops.

Decision Making

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:

  1. Evaluate an expression, returning a value, like a boolean.
  2. Perform the action(s) in the following code block(s), depending on the result.

Comparison Operators

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))

Logical Operators

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.

IF and IF-ELSE Statements

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'.