Chapter 1 · Foundations

Values and variables

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

Step 1 of 22 · Concept

A variable is a named box

By the end of this lesson you can name values and compute with them.

let age = 15;
age = 16;

let age = 15; makes a box named age in the module's frame (lesson 2), and = puts 15 in it. age = 16; puts a new value in the same box, with no let.

const width = 7;
const height = 2;
console.log("Area:", width * height);
console.log("Half:", width / height);
console.log(2 + 3 * 4);
let coins = 10;
coins += 5;
console.log("After a gift:", coins);
coins -= 3;
console.log("After a snack:", coins);
coins *= 2;
console.log("Doubled:", coins);
coins++;
console.log("Found one:", coins);
console.log(typeof coins, typeof "10", typeof true);
// 1. make price (4) and count (3)
// 2. log the count and the total
// 3. add 2 to count with +=, then log again
console.log(10 / 4);
console.log(10 / 0);
console.log(10 % 4);
console.log(Math.floor(10 / 4));
// write your program here
const bonus = 50;
let ada = 270;
let bob = 200;
ada += bonus;
bob += bonus;
console.log("Ada:", ada);
console.log("Bob:", bob);
Terminal
Step 1 of 7Area and half

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)