JavaScriptLesson 1 of 16

Your first program: console.log and comments

Every program starts by saying something. In JavaScript that is the job of console.log, which prints a value to the console.

Key points

  • console.log(…) prints what is in the brackets; each call starts a new line
  • Text goes in quotes: "double", 'single' or `backticks`
  • Numbers and sums need no quotes: console.log(2 + 2) prints 4
  • Values separated by commas are printed with spaces between them
  • // starts a comment to the end of the line, /* … */ spans several lines

Example

// A one-line comment: JavaScript skips itconsole.log("Hello, world!");console.log(2 + 2);/* A block comment   can take several lines */console.log("JavaScript", "runs", "everywhere");

Three calls, three lines. JavaScript skips the comments and works out 2 + 2 before printing it.

Task

How to use the editor⌘ Enter or Ctrl Enter runs the code, ⇧ ⌘ Enter checks the task.Tab and Shift Tab indent the line or the selection; Esc, then Tab leaves the editor.The check compares what the program printed with the task; spaces at line ends do not matter.After two failed checks you may open the solution. Your code is kept in this browser.

Mission control is ready for launch. After the line Mission: Moon, print the countdown 3, 2 and 1, one number per line, and then the line Liftoff!

Output

What your program prints appears here.