First programs

How a program runs, the kinds of values it works with, and the two tools that give programs their power: decisions and repetition. You finish by handling text and numbers with confidence.

About 11 hours of study

Learning objectives

Lessons

  1. 1

    JavaScript and the web

    What HTML, CSS and JavaScript each do in a web page, how a JavaScript program runs one statement at a time, and printing with console.log.

  2. 2

    Values, variables and types

    let, const and var; numbers, strings, booleans, null and undefined; typeof; template strings; and why === is safer than ==.

  3. 3

    Decisions: if, else and switch

    Comparisons and the logical operators, truthy and falsy values, if, else if and else, the ternary operator, switch, and reading input with prompt().

  4. 4

    Loops

    Repeating code with for, while and do...while, walking through arrays and strings with for...of, and break and continue.

  5. 5

    Working with text and numbers

    The everyday tools for strings and numbers: length and indexes, searching, cutting and changing text, splitting into words, rounding, formatting and the Math object.

Module practice

Module quiz

1. A program reads 10 with prompt() and adds 5 using +, with no conversion. What is the result?
2. Which declaration should be your default for a new variable?
3. What does this condition test: (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0?
4. An array has 5 items. Which loop condition visits each index exactly once, starting from i = 0?
5. Why is a while loop a better fit than a for loop for reading input until there is no more?
6. What is (1.005).toFixed(2) + 1?
7. After const s = " hi "; s.trim(); what is s.length?

Functions and data ›