<h1> Hello, web! </h1> { } ;( ) FIG. 01 — EVERY PAGE STARTS HERE
WEB DEVELOPMENT ACADEMY

Basic Web
Application

September 12, 2026|Lecture 01 · Online
Course roadmap

What we cover today

01Web Foundations History · what a page is made of · DevTools · libraries · VS Code setup
02HTML5 Syntax & tags · text, lists · attributes & ARIA · navigation · images · inputs
03CSS3 Styling · selectors · box model · Flexbox · Grid · position & z-index · responsive
04JavaScript Variables · types · math · control flow · loops · arrays & objects · functions · DOM
05Practice & Labs Six hands-on labs — from converting a Word article to a JavaScript calculator
Basic Web Application02 / 49
01
Web Foundations

A short history, the moving parts of the platform, and the toolkit on your machine.

HistoryAnatomy of a pageInspectLibrariesVS Code
Section 0103 / 49
Web Foundations

A brief history of the web

1989 1991 1993 1995 1996 2008 2014 Tim Berners-Lee proposes a linked system at CERN The first website goes live at info.cern.ch Mosaic — the first browser people use Brendan Eich creates JavaScript in about 10 days CSS Level 1 becomes a W3C standard Chrome launches the V8 engine HTML5 becomes a W3C Recommendation SOURCES — CERN WEB ARCHIVES · W3C HISTORY · NETSCAPE PRESS MATERIALS, 1995
Perspective: the platform is ~35 years old and still changes monthly — that is why we learn fundamentals, not fads.
Web Foundations04 / 49
Web Foundations

The web today, by the numbers

6 B
people online in 2025 — 74% of humanity
ITU, FACTS & FIGURES 2025
1.39 B
websites responded to Netcraft's Dec 2025 survey
NETCRAFT WEB SERVER SURVEY
66 %
of developers use JavaScript — the #1 language
STACK OVERFLOW SURVEY 2025

Browser market share — Aug 2026

Chrome
69.3%
Safari
15.9%
Edge
5.4%
Firefox
3.0%
Samsung Int.
2.0%
Opera
1.9%

Every engine renders HTML, CSS and JS — write to standards, not to one browser.

SOURCE — STATCOUNTER GLOBALSTATS, AUG 2026

Web Foundations05 / 49
Web Foundations

What is the web made of?

CLIENT your browser HTTP REQUEST SERVER stores pages & data RESPONSE — HTML·CSS·JS RENDER pixels on screen Your device keeps no copy of the site — it asks a server, then assembles the page from three files.

One page, three languages — three jobs:

HTMLSTRUCTURE

the skeleton — content & meaning

<h1>Welcome</h1>
<p>Course intro</p>
CSSPRESENTATION

the skin — layout, color, spacing

h1 { color: navy; }
p { margin: 8px; }
JavaScriptBEHAVIOR

the muscles — logic & reaction

button.onclick =
  () => alert("Hi!");
Web Foundations06 / 49
Web Foundations

HTML, CSS & JavaScript — one body

BRAIN → JS DRESSING → CSS SKELETON → HTML FIG. 02 — ONE BODY, THREE SYSTEMS
HTML
The skeleton

Structure that holds everything up — headings, paragraphs, images, buttons. Take it away and the body collapses.

CSS
The dressing

Clothes, colors and personality — how the body presents itself. Same skeleton, totally different style.

JAVASCRIPT
The brain & muscle

Thinks, decides, reacts and moves — behavior. It turns a body that just stands there into a living person.

Ask the class: a site with only HTML is a skeleton. Only CSS — clothes on the floor. Only JS — a brain in a jar. You need all three.

Web Foundations07 / 49
Web Foundations

Under the hood: DevTools (Inspect)

university.edu/courses university.edu ▸ Programmes ▸ Admissions ▸ Research ▸ Campus life <h2>B.Sc. Web Dev</h2> B.Sc. Web Development Apply now → Elements   Console   Network <div class="hero"> <h2>Web Dev</h2> <a href="#apply"> h2 { color: navy } FIG. 03 — YOUR BROWSER, X-RAYED (LIVE DEMO IN CLASS)

Open it three ways

  • F12 — Windows / Linux
  • ⌘⌥I — macOS
  • Right-click → Inspect — anywhere

Panels to know

  • Elements: the live DOM — click any node, see the styles
  • Console: run JavaScript right now, read errors
  • Network: every file the page downloads, with timings
  • Device bar: preview phone & tablet widths instantly
Golden rule: edits in DevTools are local and temporary — refresh and the real page returns. A perfect safe sandbox.
Web Foundations08 / 49
Web Foundations

Libraries: compose, don't rebuild

  • Library — a toolbox you call when needed: React, jQuery, Lodash
  • Framework — a scaffold that calls your code: Next.js, Angular
  • Composition — a page is HTML glued to CSS and JS with <link> and <script>
  • CDN / npm — two ways to fetch code other people wrote, tested and optimized
Today: plain HTML/CSS/JS — no libraries. But everything you learn is exactly what libraries manipulate under the hood.

HOUSEHOLD NAMES YOU WILL MEET LATER

jQueryReactVueBootstrapTailwind
index.html — composition in one file
<!-- structure -->
<h1>My portfolio</h1>

<!-- presentation: my own stylesheet -->
<link rel="stylesheet" href="styles.css">

<!-- behavior: my own script -->
<script src="script.js"></script>

<!-- a library, fetched from a CDN -->
<script
  src="https://cdn.example.com/jquery.js">
</script>
HTML — structure CSS — presentation JS — behavior LOAD ORDER MATTERS
Web Foundations09 / 49
Web Foundations

Prepare your environment

STEP 1
Install VS Code

Free at code.visualstudio.com. Built-in Emmet expands "!" into a full HTML5 boilerplate — type it, press Tab.

STEP 2
Add 3 extensions

Live Server (auto-reload browser) · Prettier (formats your code) · Auto Rename Tag (keeps tag pairs in sync).

STEP 3
Create a project folder

One folder per lab, with the three core files: index.html, styles.css, script.js.

STEP 4
Open with Live Server

Right-click index.html → "Open with Live Server". Save a file → the browser refreshes itself.

Check yourself: type an <h1>, save, and watch it appear without touching F5. If that loop works, your workflow is ready.
your first project
webdev-lab/
├── index.html    ← structure
├── styles.css    ← styling
└── script.js     ← behavior

Tip: open the FOLDER (not the file)
in VS Code — IntelliSense then
understands the whole project.
browser auto-reloads on save FIG. 04 — THE EDIT → SAVE → REFRESH LOOP
Web Foundations10 / 49
02
HTML5

The web's structure language: tags, attributes, and meaning.

SyntaxText & listsAttributes & ARIALinksImagesInputs
Section 0211 / 49
HTML5 · Chapter 02

Anatomy of an HTML page

index.html
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>My first page</title>
  </head>

  <body>
    <h1>Hello, class!</h1>
    <p>My very own page.</p>
  </body>

</html>

In VS Code, type ! and press Tab — Emmet writes this whole boilerplate for you.

< p > content < / p > OPENING TAG CONTENT CLOSING TAG ELEMENT = OPENING TAG + CONTENT + CLOSING TAG
<!DOCTYPE html> — "modern HTML", not a 1998 quirk mode.
<html lang="en"> — root element; lang helps screen readers & translation.
<head> — metadata the visitor doesn't see. <meta charset="UTF-8"> enables every character.
<body> — everything visible: text, images, buttons.
HTML512 / 49
HTML5 · Chapter 02

Working with text

article.html
<h1>Main heading</h1>
<h2>Section heading</h2>

<p>Normal <strong>bold-important</strong>
and <em>emphasised</em> text.</p>

<p>Water is H<sub>2</sub>O,</p>
<p>and 2<sup>10</sup> = 1024.</p>

<p>Press <kbd>Ctrl</kbd> + <kbd>S</kbd>
to save.<br>New line,<br>same paragraph.</p>

RENDERED RESULT

Main heading

Section heading

Normal bold-important and emphasised text.

Water is H2O, and 210 = 1024.

Ctrl + S  to save.
New line,
same paragraph.


↑ <hr> — a thematic break between topics

h1–h6: six heading levels, h1 is the most important — use ONE per page. <strong>/<em> carry meaning for screen readers; <b>/<i> are just looks.
HTML513 / 49
HTML5 · Chapter 02

Lists: ordered & unordered

lists.html
<ul>
  <li>Morning: HTML drills</li>
  <li>Afternoon: CSS layouts
    <ul>
      <li>Flexbox</li>
      <li>Grid</li>
    </ul>
  </li>
</ul>

<ol start="3">
  <li>Register the domain</li>
  <li>Deploy the site</li>
</ol>
Morning: HTML drills Afternoon: CSS layouts Flexbox Grid 3.  Register the domain 4.  Deploy the site UL = DOTS · OL = NUMBERS · NESTING GOES INSIDE <LI>
Choosing: <ul> for menus, features, anything unordered · <ol> for steps, rankings, recipes · <ol start="3"> begins counting at 3.
HTML514 / 49
HTML5 · Chapter 02

Attributes & accessibility (ARIA)

<img  src="cat.jpg"  alt="A sleeping orange cat"  width="300">
element — <img> is empty,
no closing tag
attribute =
name + value in quotes
alt — read aloud to blind users,
shown when the image fails
size in pixels —
prevents layout jump

Global attributes — every element

  • id="header" — unique; one per page, for #links & JS
  • class="card" — reusable style hook, shared by many
  • title="…" — tooltip on hover
  • lang, style, hidden — language, inline CSS, visibility

ARIA — when HTML alone isn't enough

  • role="button" — a <div> behaving like a button (last resort)
  • aria-label — name an icon-only link for screen readers
  • aria-hidden="true" — hide decoration from assistive tech
  • Rule: semantic HTML first — ARIA is seasoning, not flour
HTML515 / 49
HTML5 · Chapter 02

Links & navigation

nav.html
<nav>
  <a href="index.html">Home</a>
  <a href="pages/about.html">About</a>
  <a href="https://developer.mozilla.org"
     target="_blank" rel="noopener">MDN</a>
  <a href="#contacts">Contacts ↓</a>
</nav>

<!-- ...page content... -->

<section id="contacts">
  <h2>Contact us</h2>
</section>
relative — same site absolute — the whole web anchor — jumps inside this page new tab — target="_blank" ALWAYS PAIR target="_blank" WITH rel="noopener"
Default look: blue + underlined — CSS (section 03) restyles them. A nav bar is just a styled list of links.
HTML516 / 49
HTML5 · Chapter 02

Images

gallery.html
<figure>
  <img src="images/campus.jpg"
       alt="Students on orientation day"
       width="320" height="180"
       loading="lazy">
  <figcaption>
    Orientation day, Sept 2026
  </figcaption>
</figure>

<!-- always: folder path, alt text, -->
<!-- and explicit dimensions -->
Orientation day, Sept 2026 — the caption JPG photos, millions of colors PNG transparency, sharp edges SVG logos & icons — scales forever WebP modern default — smallest
Three habits: keep images in a folder (src="images/…") · ALWAYS write alt · set width & height so the page doesn't jump while loading.
HTML517 / 49
HTML5 · Chapter 02

Forms & inputs

signup.html
<label>Email
  <input type="email"
         placeholder="you@univ.edu">
</label>
<label>Password
  <input type="password">
</label>

<input type="checkbox" checked> Remember me
<input type="radio" name="year"> Year 1
<input type="radio" name="year"> Year 2

<label>Deadline <input type="date"></label>
<textarea rows="3"></textarea>
<button>Sign up</button>
RENDERED CONTROLS you@univ.edu •••••••• Remember me Year 1 Year 2 2026-09-10 Deadline Sign up TYPE="EMAIL" VALIDATES BEFORE JS EVEN RUNS
Why type matters: the right keyboard on mobile + free validation. Wrap inputs in <label> — big tap target + screen-reader name. Same name on radios = one choice only.
HTML518 / 49
Lab 1 · HTML5 practice

From Word to the web

Lab 1 · Convert a Word article to HTML5

Title / Heading 1 <h1>
Heading 2 <h2>
Body paragraph <p>
Bold text <strong>
Italic text <em>
Bullet list <ul> + <li>
Numbered steps <ol> + <li>

Workflow

semantic.html
<nav>…</nav>
<section id="ch-1">
  <h2>Chapter one</h2>
  <p>Retyped, not pasted.</p>
</section>
  • Workflow: open the article side-by-side, retype (don't paste) the structure
  • Add: boilerplate, lang, charset, a nav bar, one image with alt
  • Semantic: wrap chapters in <section>, the menu in <nav>
Deliverable: one valid, semantic HTML5 page of the article — headings, lists, nav and one image with alt.
Practice & Labs19 / 49
03
CSS3

The web's presentation language: from colors and fonts to full page layouts.

SyntaxSelectorsBox modelFlexboxGridPosition & z-indexResponsive
Section 0320 / 49
CSS3 · Chapter 03

CSS syntax: rules, and where they live

h1 { color: navy; font-size: 32px; }
selector — which elements?
(next slide)
declaration = property : value ;
semicolon between them
values carry units:
32px, 1.6, #1572b6, 50%

Three ways to attach CSS — and the one to use:

INLINE

style="color:navy"

inside the HTML tag

Avoid — mixes jobs, can't be reused

INTERNAL

<style> h1 {…} </style>

inside <head> of the page

Fine for quick single-page demos

EXTERNAL ✓

<link rel="stylesheet"
      href="styles.css">

a separate .css file

The professional default: reuse + caching

CSS321 / 49
CSS3 · Chapter 03

Selectors: target anything

Pattern Type Matches
h1 element every <h1> on the page
.card class every element with class="card"
#header id the one element with id="header"
nav a descendant links inside <nav> — parents first, space, child
a:hover pseudo-class a link the mouse is currently over
h1, p grouped same style to h1 AND p in one rule
Class is king: default to .classes; ids only for one-off anchors; elements for global resets.

When rules fight — specificity decides:

id — #header   100 pts
class — .card  10 pts
element — h1  1 pt
  • Tie? the rule written LATER wins
  • Inline style beats everything (except !important)
  • !important wins the fight — and your debuggability. Avoid.
CSS322 / 49
CSS3 · Chapter 03

The box model: every element is a box

MARGIN — OUTSIDE, TRANSPARENT, PUSHES NEIGHBOURS BORDER PADDING — BREATHING ROOM INSIDE CONTENT 240 × 120 FIG. 05 — EVERY ELEMENT IS A NESTED BOX · SEE IT LIVE IN DEVTOOLS

Total width surprises beginners:

default width + padding + border
= wider than you asked

* { box-sizing: border-box; }

put this in every project — width then includes padding + border, which is what you always meant anyway.

DevTools: Inspect any element → the colored box-model diagram is drawn for you, live.
CSS323 / 49
CSS3 · Chapter 03

Styling: color, fonts & effects

styles.css
.card {
  color: #1f2430;
  background: #eaf3fa;
  font-family: Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  text-align: center;
  border-radius: 16px;
  box-shadow: 0 8px 24px
              rgba(0,0,0,.15);
  transition: transform .3s;
}
.card:hover { transform: scale(1.05); }

WRITING COLORS — FOUR NOTATIONS, ONE BLACK

#111111rgb(17 17 17)rgba(17,17,17,1)hsl(0 0% 7%)

Orientation Day

Join us on campus — tours at 10:00 and 14:00.

hover me → grows smoothly (transition)

transition + :hover = your first animation, three lines, no JavaScript. The hover shadow above is box-shadow: 6px 6px 0 #E6E6E6 — a hard offset, the minimalist's shadow.

CSS324 / 49
CSS3 · Chapter 03

Flexbox: one-dimensional layout

.container { display: flex } 1 2 3 MAIN AXIS → justify-content CROSS AXIS ↓ align-items

The five properties you actually need

display: flexturns children into flex items, in a row
flex-directionrow (default) or column — the axis
justify-contentmain axis: flex-start · center · space-between
align-itemscross axis: stretch · center · flex-end
gapfixed spacing between items — no margin hacks
Practice after class: flexboxfroggy.com — 24 levels drilling exactly these. Levels 1–12 tonight, all 24 by next week.
CSS325 / 49
CSS3 · Chapter 03

Grid: two-dimensional layout

rows × columns at once — place items in cells

gallery.css
.gallery {
  display: grid;
  grid-template-columns:
    repeat(3, 1fr);
  gap: 16px;
}

1fr = one fraction of the free space — three of them make three equal columns. Change 3 → 2 and the layout reflows — the same trick you will reuse for photo galleries.

Flexbox

one row OR column · content decides size · navbars, button rows

Grid

rows AND columns · layout decides size · page shells, galleries, calculators

They compose: grid for the page skeleton, flexbox inside each cell.

CSS326 / 49
CSS3 · Chapter 03

Position & z-index: layers and overlaps

static default — normal flow; offset properties are ignored
relative stays in flow, can be nudged (top/left) — and anchors absolute children
absolute removed from flow; pinned to the nearest positioned ancestor
fixed pinned to the viewport — stays put while scrolling (cookie banners)
bubble.css — overlap preview
.cube {
  position: relative;
  z-index: 1;
}
.cube:hover { z-index: 5; }

z-index decides who is on top

higher = closer to the viewer. Only positioned (or flex/grid) items stack.

z-index: 1 — card z-index: 2 — modal z-index: 3 — badge (top)
Recipe: parent relative + child absolute = precise placement for badges, bubbles, stickers.
CSS327 / 49
CSS3 · Chapter 03

Responsive: one page, every screen

responsive.html + styles.css
<!-- in <head>: the magic line -->
<meta name="viewport"
      content="width=device-width,
               initial-scale=1">

/* styles.css: adapt at breakpoints */
@media (max-width: 600px) {
  .menu { flex-direction: column; }
  h1 { font-size: 28px; }
}
Why: over 60% of web traffic is mobile. No viewport meta = the phone shows a zoomed-out desktop page — the #1 beginner bug.
Phone 375 px · 1 column Tablet 768 px · 2 columns Desktop 1280 px · 3 columns
  • Mobile-first: style for the phone, add @media (min-width:…) to enhance
  • Fluid units: %, rem, vw — plus max-width: 100% on images
  • Flex/Grid wrap: let rows reflow instead of hard-coding widths
CSS328 / 49
Lab 2 · CSS3 practice

Page background — your first CSS

styles.css
/* rule one: experiment in DevTools
   first, then copy the winner here */
body {
  background: linear-gradient(
    160deg, #ffffff, #e9e9e9 60%);
}

/* same spot, other options: */
/* background: #f0f0f0;        */
/* background: url(paper.jpg); */
  • Three options: solid color · gradient · image (with a fallback color)
  • Gradient: two or more colors + an angle (160deg = top-left → bottom-right)
  • Contrast: text must stay readable on the new background — check twice
file:///lab2.html

Orientation Day

The Lab 1 article, now wearing its first CSS.

text stays readable on the light end
Deliverable: the Lab 1 article page — now wearing a background you can defend in one sentence.
Practice & Labs29 / 49
Lab 3 · CSS practice

CSS art: cube, bubble & transition

Lab 3 · Draw with CSS, then animate

art.css
/* a cube is a square + shadow */
.cube {
  width: 120px; aspect-ratio: 1;
  background: #111;
  border-radius: 12px;
  box-shadow: 8px 8px 0 #d9d9d9;
  transition: transform .3s;
}
.cube:hover { transform: rotate(8deg); }

/* the bubble's tail is a triangle */
.bubble::after { content: "";
  position: absolute; bottom: -12px;
  border: 12px solid transparent;
  border-top-color: #111; }
.CUBE — HOVER ROTATES 8° Hello! Hi, I'm the reply. ::AFTER BORDER-TRIANGLE TAIL
Next — Lab 4: Flexbox Duck, playable right inside this deck — one level per slide. Type the CSS value and bring every duck home.
Practice & Labs30 / 49
Lab 4 · CSS practice — Level 1 of 5

Flexbox Duck — Level 1

.pond { 
LEVEL 1 / 5
The rings are on the RIGHT edge — move the whole row to them.
  • Type the missing value in the code line — press Enter or Apply
  • Stuck? tap a suggestion below the code line
  • Win: every duck floats on its ring

Typed values are real CSS — even a wrong one moves the pond. Experiment freely; Reset puts it back.

Practice & Labs31 / 49
Lab 4 · CSS practice — Level 2 of 5

Flexbox Duck — Level 2

.pond { 
LEVEL 2 / 5
Ducks like the middle. Center the row.
  • Type the missing value in the code line — press Enter or Apply
  • Stuck? tap a suggestion below the code line
  • Win: every duck floats on its ring

Typed values are real CSS — even a wrong one moves the pond. Experiment freely; Reset puts it back.

Practice & Labs32 / 49
Lab 4 · CSS practice — Level 3 of 5

Flexbox Duck — Level 3

.pond { 
LEVEL 3 / 5
One left, one middle, one right — spread them out.
  • Type the missing value in the code line — press Enter or Apply
  • Stuck? tap a suggestion below the code line
  • Win: every duck floats on its ring

Typed values are real CSS — even a wrong one moves the pond. Experiment freely; Reset puts it back.

Practice & Labs33 / 49
Lab 4 · CSS practice — Level 4 of 5

Flexbox Duck — Level 4

.pond { 
LEVEL 4 / 5
Think perpendicular — stack the row into a column.
  • Type the missing value in the code line — press Enter or Apply
  • Stuck? tap a suggestion below the code line
  • Win: every duck floats on its ring

Typed values are real CSS — even a wrong one moves the pond. Experiment freely; Reset puts it back.

Practice & Labs34 / 49
Lab 4 · CSS practice — Level 5 of 5

Flexbox Duck — Level 5

.pond { 
LEVEL 5 / 5
Stack them AND spread them from top to bottom.
  • Type the missing value in the code line — press Enter or Apply
  • Stuck? tap a suggestion below the code line
  • Win: every duck floats on its ring

Typed values are real CSS — even a wrong one moves the pond. Experiment freely; Reset puts it back.

Practice & Labs35 / 49
04
JavaScript

The web's programming language: from variables to manipulating the page itself.

VariablesTypesMathControl flowLoopsArrays & objectsFunctionsDOM
Section 0436 / 49
JavaScript · Chapter 04

Variables: let, const, var

Keyword Reassign? Redeclare? Scope When to use
const no no block DEFAULT choice — values that never change
let yes no block values that WILL be reassigned (score, counters)
var yes yes function legacy 1995–2015 — you'll meet it in old code; don't write it
Rule of thumb: start with const. Switch to let the moment you need to reassign. Pretend var doesn't exist.
1995: var

2015:
let, const
variables.js
const courseName = "Web Development";   // fixed
let score = 0;                          // will change
score = score + 10;                     // now 10
JavaScript37 / 49
JavaScript · Chapter 04

Data types & typeof

7 primitives …

string "Ada" text in quotes — or backticks
number 42 · 3.14 integers and decimals, one type
boolean true · false the two logic values
undefined not set "no value yet"
null empty "we cleared it on purpose"
bigint 9007…993n astronomically big integers
symbol Symbol("id") rare — unique identifiers
Strings with superpowers: backtick template literals: `Total: ${price} baht` — interpolation without + concatenation.

… plus one composite:

typeof.js
console.log(typeof "hello");  // string
console.log(typeof 42);        // number
console.log(typeof true);      // boolean
console.log(typeof undefined); // undefined
console.log(typeof null);      // object !
console.log(typeof [1, 2, 3]); // object
console.log(typeof {a: 1});    // object

// objects bundle many values:
const student = { name: "Ada" };
Historic bug: typeof null says "object" — a 1995 type-tag mistake kept so old sites don't break. null is NOT an object.
JavaScript38 / 49
JavaScript · Chapter 04

Math operations & operators

Operators you'll use daily

+  -  *  / the classics: 7 * 6 → 42
% remainder: 7 % 2 → 1 — even/odd, cycles
** power: 2 ** 10 → 1024
+=  -=  *=  ++ shortcuts: score += 10 ≡ score = score + 10
+ on strings "5" + 2 → "52" — JS glues instead of adds!
Watch out: input fields return STRINGS. Convert before math: Number(input.value) or parseInt("42px") → 42.
math.js
const price = 19.99, qty = 3;
const total = price * qty;      // 59.97

total.toFixed(2);               // "59.97"

Math.round(4.6);                // 5
Math.floor(4.9);                // 4
Math.ceil(4.1);                 // 5

// random die: 1..6
Math.floor(Math.random() * 6) + 1;

const msg = `Total: ${total}`;  // template
Why it matters: a calculator page is 90% of this slide — read strings, convert, compute, display.
JavaScript39 / 49
JavaScript · Chapter 04

Control flow: making decisions

check score score >= 50 ? TRUE "pass" FALSE "retake" THE DIAMOND IS THE IF — CODE BRANCHES EXACTLY LIKE THE DIAGRAM
=====!==&& || !< > <= >=
grades.js
if (score >= 50) {
  grade = "pass";
} else if (score >= 40) {
  grade = "retake";
} else {
  grade = "fail";
}

// many exact values? use switch:
switch (day) {
  case "Sat":
  case "Sun": off = true; break;
  default: off = false;
}
Truthy / falsy: 0, "", null, undefined, NaN behave like false; everything else like true. And remember: === strict beats == loose ("5" == 5 is true, "5" === 5 is false).
JavaScript40 / 49
JavaScript · Chapter 04

Loops: repeat without repeating yourself

for ( let i = 0; i < 5; i++ ) { console.log(i); }
keep going while i < 5 START — let i = 0 (runs once) STEP — i++ after every turn FIG. 06 — THE LOOP WHEEL: START → CONDITION → BODY → STEP → CONDITION → …
loops.js
// counted: 0, 1, 2, 3, 4
for (let i = 0; i < 5; i++) {
  console.log("Cube " + i);
}

// unknown count: while
let hp = 100;
while (hp > 0) { hp -= 25; }

// walk an array: for...of
for (const c of colors) show(c);
foryou know how many times
whilerepeat UNTIL something happens
break / continueexit early / skip one turn
Why loops matter: one loop stamps 100 cubes onto the page — imagine copy-pasting 100 divs by hand instead.
JavaScript41 / 49
JavaScript · Chapter 04

Arrays: ordered collections

"red" "green" "blue" "gold" "teal" 0 1 2 3 4 colors[0] is the FIRST item — counting starts at 0, the #1 beginner surprise. colors.length → 5
arrays.js
const colors = ["red", "green", "blue"];

colors[0];             // "red"
colors.length;         // 3
colors[1] = "lime";    // replace

colors.push("gold");   // add to end
colors.pop();          // remove from end
colors.includes("red") // true

colors.join(" · ");    // "red · lime · blue"
  • Ordered: items keep their position — use [index] to reach any of them
  • Mixed: one array may hold strings, numbers, even other arrays
  • const arrays mutate: const stops REASSIGNMENT, not push/pop
  • Loop over it: for (const c of colors) — every item, in order
Recipe to remember: array of settings + one loop = many DOM elements, zero copy-paste.
JavaScript42 / 49
JavaScript · Chapter 04

Objects: describing real things

const student = { … } name "Ada" year 2 gpa 3.86 skills ["html","css"] active true A KEY DESCRIBES A PROPERTY — LIKE A LABELED DRAWER
objects.js
const student = {
  name: "Ada", year: 2, gpa: 3.86,
  skills: ["html", "css"],
};

student.name;         // "Ada"  (dot)
student["gpa"];       // 3.86   (bracket)
student.skills.push("js");

// arrays of objects = a mini database:
const students = [
  { name: "Ada",  year: 2 },
  { name: "Bo",   year: 3 },
];
students[1].name;     // "Bo"
The big idea: each cube = one object { color, size, x } inside an array. Change the data → the page changes. This is exactly how React props feel later.
JavaScript43 / 49
JavaScript · Chapter 04

Functions: reusable recipes

functions.js
// declaration: name + parameters
function calcArea(width, height) {
  const area = width * height;
  return area;        // hand back
}

// call it with arguments:
const a = calcArea(3, 4);   // 12
const b = calcArea(10, 2);  // 20

// arrow function — same idea, shorter:
const calcArea2 = (w, h) => w * h;
calcArea2(5, 5);            // 25

On a calculator page, every key calls the SAME function with a different argument.

INPUTS 3 × 4 calcArea(w, h) runs the recipe once per call RETURN 12 PARAMETERS (W, H) ARE PLACEHOLDERS — ARGUMENTS (3, 4) FILL THEM IN
Why functions: write once, call anywhere — the calculator's compute() runs on every button press. No return means undefined.
JavaScript44 / 49
JavaScript · Chapter 04

The DOM: JavaScript meets your HTML

document <html> <head> <body> <meta> <title> <h1> <button> FIG. 07 — THE BROWSER READS YOUR HTML INTO THIS LIVING TREE
1 select2 listen3 change4 create — behind every interactive page
dom.js
// 1  select the button
const btn = document.querySelector("#go");

// 2  listen for events
btn.addEventListener("click", () => {
  // 3  change what is on screen
  const cube = document.querySelector(".cube");
  cube.classList.toggle("spin");

  // 4  create & attach new content
  const p = document.createElement("p");
  p.textContent = "Clicked!";
  document.body.append(p);
});

The calculator = moves 1–3 · the cube farm = move 4, in a loop

JavaScript45 / 49
Lab 5 · JavaScript practice

A JavaScript calculator page

  • Layout: display + 4×4 keypad — one CSS grid (slide 24)
  • Wiring: every key calls the same function (slide 35)
  • Compute: read the display string, convert with Number (slide 30)
calculator.js
const keys = document.querySelectorAll(".key");
const display = document.querySelector("#screen");

keys.forEach(k =>
  k.addEventListener("click", () =>
    display.value += k.textContent));

equalBtn.addEventListener("click", () =>
  display.value = compute(display.value));
// compute(): parse left, op, right → return result
1,234 C +/− % ÷ 7 8 9 × 4 5 6 1 2 3 + 0 . =
Practice & Labs46 / 49
Lab 6 · JavaScript practice

Clone with data, not copy-paste

The brief: fill the stage with 100 cubes and a conversation of bubbles — by changing DATA, never by duplicating HTML.

populate.js
// 1 the data — one object per cube
const cubes = [
  { color: "#111",  size: 90, x: 20 },
  { color: "#7a7a7a", size: 60, x: 140 },
  { color: "#c9c9c9", size: 120, x: 230 },
];

// 2 the loop — one recipe, N elements
for (const cfg of cubes) {
  const div = document.createElement("div");
  div.className = "cube";
  div.style.background = cfg.color;
  div.style.width = cfg.size + "px";
  div.style.left = cfg.x + "px";
  stage.append(div);
}

Deliverable: a page that renders 100+ styled elements from a single array.

↑ the loop renders the array CHANGE THE DATA — THE PAGE FOLLOWS. THIS IS HOW REACT FEELS.
  • 100 cubes: add 97 objects to the array — the loop is already done
  • Randomness: Math.random() inside the loop gives every cube a size
  • Bubbles: array of { who, text } → a chat conversation
  • Thinking shift: HTML describes ONE item; data + loop make MANY
Practice & Labs47 / 49
Practice & Labs · Recap

Six labs, one thread

LAB 1
Word → HTML5

Convert a real Word article into a clean, semantic HTML5 page.

LAB 2
Page background

Style the page: solid color, gradient — first taste of CSS.

LAB 3
CSS art

Draw a cube and a message bubble in pure CSS, then animate them.

LAB 4
Flexbox Duck

5 levels of a game that drills justify-content and flex-direction.

LAB 5
Calculator page

A working calculator: buttons, display, and the JS behind them.

LAB 6
Loop cloning

Generate 100 cubes & bubbles from an array — no copy-paste.

Submission: each lab = one folder (index.html + styles.css + script.js), zipped, on the course portal before the next session.
Practice & Labs48 / 49
WEB DEVELOPMENT ACADEMY

You can now
build the web.

Structure it with HTML. Style it with CSS. Make it think with JavaScript.
Then practice until it feels like handwriting.

KEEP THESE OPEN FOREVER

MDN Web Docs

developer.mozilla.org

Flexbox Froggy

flexboxfroggy.com — all 24 levels

freeCodeCamp

freecodecamp.org — the full free curriculum

Can I use

caniuse.com — browser support

Questions?

← → to navigate · P to print
1 / 1