Values and Variables

Programs work with values: a price, a name, a yes or no. Learn to keep them in variables with let and const, calculate with numbers, build text with template literals, compare values, and convert between types when a number arrives as text.

Updated

Variables in JavaScript

  1. Variables with let and const (Novice): A variable gives a value a name so your program can remember it, and let or const says whether that value is allowed to change.

Numbers in JavaScript

  1. Numbers and Math (Novice): Work out totals, remainders and powers with JavaScript's arithmetic operators, in the order JavaScript does, and round money so it shows as dollars and cents.

Text in JavaScript

  1. Strings and Template Literals (Novice): Store text in strings, build messages from your values with template literals, and tidy and search text with length, trim, toUpperCase and includes.

True or False in JavaScript

  1. Booleans and Comparisons (Novice): Ask yes-or-no questions about your values with comparisons such as === and >=, and keep the true or false answer in a well-named boolean.

JavaScript Types

  1. Types and Converting Between Them (Apprentice): Tell numbers, strings and booleans apart with typeof, turn text into numbers and back with Number() and String(), and know why '5' + 3 is '53' and where NaN comes from.

Exercise: Coffee Shop Receipt

  1. Exercise: Coffee Shop Receipt (Novice): Finish six small functions that work out a coffee shop receipt's subtotal, tax, tip and lines, using numbers, strings, comparisons and conversions, and let the tests check each one.