reading-notes

Building Better Web Pages with Semantic HTML

Using “semantic” elements means choosing HTML tags that describe the purpose of the content rather than just how it looks. Think of it like labeling boxes in a moving truck: labeling a box “Kitchen Utensils” is much more helpful than just labeling it “Box 1.”

Why Semantic Elements Matter

Instead of using generic tags for everything, using specific elements provides several big wins:

Organizing Content with Headings

HTML gives us six levels of headings, from <h1> down to <h6>. You can think of these like the chapters and sub-sections of a non-fiction book.

Pro Tip: Try to stick to just two or three heading levels (<h1>, <h2>, and <h3>) to keep your page from becoming too cluttered or confusing.

Special Text: Superscript and Subscript

Sometimes text needs to be smaller and shifted up or down. We use <sup> (superscript) and <sub> (subscript) to handle this professionally.

Explaining Abbreviations

When you use an abbreviation or an acronym that people might not know, use the <abbr> tag. To make it helpful, add a title attribute.

When a user hovers their mouse over the text, the full meaning will pop up. This is great for technical terms or organization names.

Example: <abbr title="National Aeronautics and Space Administration">NASA</abbr>

Learn CSS

There are three common ways to apply CSS to an HTML document:

Why to Avoid Inline Styles

You should avoid using inline styles whenever possible because they are considered bad practice for several reasons:

Code Block Review

Here is a breakdown of the following CSS code block:

h2 { color: black; padding: 5px; }

JavaScript Essentials: The Building Blocks of Interactivity

JavaScript is the “brain” of a website. While HTML provides the structure, JavaScript handles the logic and the data.

How JavaScript Handles Text (Strings)

In programming, any sequence of characters (letters, numbers, or symbols) used as text is called a String.

Think of a String like a “string” of beads, where each bead is a character. To tell the computer where the text starts and ends, we wrap it in quotes.

Common Tools: Operators

An operator is a symbol that performs an action on your data. Here are four essential types you will use constantly:

Operator Name What it does Example
+ Addition Combines two numbers or joins two strings together. 10 + 5 or "Cold" + "Brew"
- Subtraction Takes one value away from another. 100 - 20
! Logical NOT Flips a value (True becomes False). Useful for “If NOT logged in…” !true
=== Strict Equality Checks if two things are exactly the same. userChoice === "Option A"

Solving Real-World Problems with Functions

A function is a “recipe” for code. You write the instructions once, and then you can “cook” that recipe whenever you need it without rewriting the steps.

Functions are used to solve common website challenges, such as:

Making Decisions: Conditional Logic in JavaScript

JavaScript uses “Conditionals” to decide which code to run. It works exactly like a flow chart: if a certain door is open, the code walks through it; if not, it tries the next one.

How JavaScript Makes Choices**

if Statement: This is your primary test. It checks a specific condition. If that condition is true, the code inside the curly braces { } runs. If it’s false, JavaScript simply skips over it.

else if Statement: Think of this as your “Plan B” or “Plan C.” You use these to chain multiple choices together. You can have as many else if blocks as you want to handle different scenarios between your first choice and your final fallback.

Comparing Values (Comparison Operators)**

To make decisions, JavaScript needs to compare different pieces of data. Here are the tools it uses to do that:

Tool What it checks Example
=== and !== Equality & Inequality: Is this exactly the same, or is it definitely different? status === "active"
< and > Size Comparison: Is one number smaller or larger than the other? price < 50
<= and >= Limits: Is a value within a certain range (including the number itself)? age >= 18

Combining Tests (Logical Operators)**

Sometimes one test isn’t enough. You might need to check two or three things at once before making a decision. This is where Logical Operators come in.

&& (The “AND” Operator):

This operator is strict. For the whole thing to be true, every single part must be true.

|| (The “OR” Operator):

This operator is more relaxed. The whole thing is true if at least one part is true.