Lesson 1 · Unit 01
Values and expressions
Numbers, text, console.log and arithmetic, one statement at a time
What you practise
- Numbers and text,
console.log, arithmetic and its order,%and**, strings in quotes, one statement at a time
Try a question from this lesson
Pick one
This one line is a whole program. What do you think it puts on the screen?
console.log(2 + 3);Correct answer
5
Why
console.log(...) shows whatever is inside its brackets. JavaScript works out 2 + 3 first, then shows the result. It does not show the sum as you typed it.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Your first program
A program is a list of instructions. Each instruction is called a statement and ends with a semicolon.
JavaScript runs the statements one at a time, from the top to the bottom.
console.log(...) is a statement that prints what is inside its brackets, on a new line each time.
console.log(1);
console.log(2);
console.log(3);Concept
Arithmetic
+ - * / are add, subtract, multiply and divide. * and / go before + and -. Brackets go before everything.
Dividing can give a decimal: 7 / 2 is 3.5.
Anything after // is a comment: a note for people. JavaScript skips it.
console.log(7 / 2); // 3.5
console.log(2 + 3 * 4); // 14
console.log((2 + 3) * 4); // 20Concept
Text is a string
Text goes in quotes, and is called a string. The quotes mark where the text starts and ends. They are not printed.
Without quotes, JavaScript reads what you wrote as a calculation or a name.
+ between two strings joins them, exactly as they are. It adds no space.
console.log("Hi there"); // Hi there
console.log("Hi" + "there"); // Hithere
console.log("7" + "2"); // 729 more exercises in the app
- 3× type the answer
- 3× multiple choice
- 1× true or false
- 1× fill the blanks
- 1× order the lines
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.