Chapter 5 · The web page

A web page

You are reading the whole lesson on one page. Back to one step at a time

Step 1 of 22 · Concept

Your first web page

By the end of this lesson you can:

  • write a web page in HTML,
  • style it with CSS,
  • change it from JavaScript.

It is the same JavaScript as in lessons 1–20. Now it runs in a web page, and Run shows that page in the Page tab.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Shopping</title>
</head>
<body>
  <h1>Shopping</h1>
  <p>Three things to buy.</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Shopping</title>
</head>
<body>
</body>
</html>
#title {
  border: 2px solid black;
  padding: 8px;
}

.done {
  color: gray;
}
#title {
  border: 2px solid black;
  padding: 8px;
}
const title = document.querySelector("#title");
console.log(title.textContent);
title.textContent = "My list";
console.log(title.textContent);
console.log(document.querySelectorAll("li").length);
const items = document.querySelectorAll("li");
items[0].classList.remove("done");
items[1].classList.add("done");
items[2].classList.toggle("done");
const tasks = [
  { title: "Buy milk", done: true },
  { title: "<b>Tea</b>", done: false },
  { title: "Call Bo", done: false },
];
const list = document.querySelector("#list");
document.querySelector("#empty").remove();
for (const task of tasks) {
  const item = document.createElement("li");
  item.textContent = task.title;
  if (task.done) {
    item.classList.add("done");
  }
  list.append(item);
}
console.log(`Added ${tasks.length} items`);
const todos = [
  { title: "Water plants", done: false },
  { title: "Buy milk", done: true },
  { title: "Call Bo", done: false },
];
// 1. find the ul whose id is todos
// 2. one li per task, its text the title
// 3. the class done on the done ones
const players = [
  { name: "Ada", score: 90 },
  { name: "Alan", score: 85 },
  { name: "Grace", score: 95 },
];
const total = document.querySelector("#total");
// add up the prices, then show the total
Terminal
Step 1 of 10Your first page

Keyboard shortcuts

The step

ContinueEnter
Previous / next stepAlt+[ · Alt+]
Move along the steps bar← → Home End, then Enter
From a quiz's title to its answers↓
Skip to the stepTab, then Enter (first on the page)
Course outlineAlt+O
These shortcuts?

The workspace

Run the stepCtrl+Enter (⌘↵ on a Mac)
Lesson → editor → consoleF6 (Shift+F6 back)
Output ↔ TerminalCtrl+`
Focus the editorCtrl+. (⌘. on a Mac)
Hide or show the lessonAlt+L
Restore, close a messageEsc (outside the editor and the terminal)

The editor

Leave the editorF6 (Shift+F6 back); or Ctrl+M (⌃⇧M on a Mac), then Tab moves the focus (not in the vim mode)
Open a file by nameCtrl+P (⌘P on a Mac)
All commandsCtrl+Shift+P (⌘⇧P on a Mac) or F1
Go to a lineCtrl+G (⌃G on a Mac)
Show or hide the filesCtrl+B (⌘B on a Mac)
Previous / next file tabCtrl+Shift+[ · Ctrl+Shift+] (⌘⇧[ · ⌘⇧] on a Mac)
The file tabs← → Home End on a tab; Delete closes it
Save the files nowCtrl+S (⌘S on a Mac)
Go to a symbol in the fileCtrl+Shift+O (⌘⇧O on a Mac)
Go to the definitionF12
Format the fileCtrl+Shift+F (⌘⇧F on a Mac), or Shift+Alt+F
Go back / forward after a jumpAlt+← · Alt+→ (⌃- · ⌃⇧- on a Mac)