A program is a list of instructions that the computer carries out one after another, from top to bottom. Each instruction is called a statement.
Your first statement prints a message:
console.log("Hello, world!");
console.logis a built-in tool that shows whatever you give it in the console, the output panel under the editor.- The text in quotes is called a string. The quotes mark where it starts and ends, and are not printed.
- The semicolon ends the statement, like a full stop ends a sentence.
You can print numbers too. Numbers have no quotes, and JavaScript can calculate with them:
console.log(42);
console.log(2 + 3);
That prints 42 and then 5.
Comments
A line that starts with // is a comment. The computer skips it. Comments are notes for the people reading the code, including you next month.
// This line does nothing
console.log("This line prints");
Press Run (or Ctrl+Enter) to run your code. Try the starting code now.
Your Task
- Change the first message so it prints exactly
Hello, world! - Add a second
console.logthat prints your name as a string. - Add a third one that prints the result of
7 * 6(use*to multiply). Let JavaScript do the math.
- The first line printed is
Hello, world! - The second line printed is some text
- The third line printed is
42, worked out by JavaScript
Lesson complete!
Next Lesson: Variables