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
- Write programs that read input and print results
- Predict what happens when values of different types are mixed
- Control a program with conditions and loops
- Clean up text and format numbers
Lessons
- 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
Values, variables and types
let, const and var; numbers, strings, booleans, null and undefined; typeof; template strings; and why === is safer than ==.
- 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
Loops
Repeating code with for, while and do...while, walking through arrays and strings with for...of, and break and continue.
- 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
- Greet the userEasy
- One line of a receiptMedium
- Days, hours and minutesHard
- Number or text?Easy
- Celsius to FahrenheitMedium
- A careful adderHard
- Even, odd or zeroEasy
- Leap yearMedium
- Cinema ticket priceHard
- FizzBuzzEasy
- Steps to reach oneMedium
- All the primes up to nHard
- Initials from a nameEasy
- Title CaseMedium
- A Caesar cipherHard