alphaPlan · Data Structures, Algorithms & the Web · Cheat-sheet 06
A first taste of the web
Build a real page by hand: HTML for structure, CSS for looks, JavaScript for behaviour, and the DOM to join them.
Ideas to remember
- 01HTML is not a programming language; it describes the structure of a page with tags that open, close and nest without crossing.
- 02Everything the visitor sees lives inside body; head holds information about the page, such as the title on the browser tab.
- 03Lists use ul or ol with li items, images use img with src and alt, and links use a with href.
- 04A CSS rule is a selector plus declarations of property: value; and it lives in its own file linked from the head.
- 05JavaScript gives a page behaviour with let and const variables, functions that return a result, and console.log to check values.
- 06The DOM is the live model of the page; getElementById and textContent let a click change what the visitor sees without a reload.
Words
- <p>This is a paragraph.</p>
- An opening tag, the content, and a closing tag with a slash; br and hr are empty tags with no closing partner.
- <h1> to <h6>
- Six heading sizes; pick the level for what it means, not for how big it looks.
- p { color: green; }
- Selector p, property color, value green; the semicolon at the end of each declaration matters.
- let, const
- let creates a variable whose value can change later; const creates one that must not.
- document.getElementById
- Fetches the element with that id so you have a handle to work with.
- textContent
- The property that reads or replaces the words inside an element; setting it changes the screen at once.
Do this
- Close tags in the reverse order you opened them: open A, open B, close B, close A.
- Write a real alt for every image and link text that says where the link goes.
- Link the stylesheet from the head with a link tag so one file dresses every page.
- Load script.js at the end of the body so the browser builds the page before your code runs.
- Reach for console.log whenever you want to check what a value actually is.
Watch out
- CSS reports no errors; a missing semicolon or a misspelled property like colour is silently skipped.
- A function with no return hands back nothing.
- If a click does nothing, check that the id in getElementById and the function name in onclick match the HTML character for character.
Found something unclear, outdated or improvable? Suggest an improvement