Skip to content

Exercise 1 of 10 · Output

Hello, Out Loud

What you will make

A four-line banner with your own name inside it, put on the screen by JavaScript you ran yourself.

The one new idea: console.log() puts text on the screen

Almost everything you write from here on has to show you something. console.log is how JavaScript answers back, and it is still the first thing working developers reach for when they want to know what their code is really doing.

Go straight to the code ↓

What console.log does

A program tells you nothing unless you ask it to. In JavaScript, console.log is how you ask.

Whatever you put between the round brackets of console.log(...) gets shown on the screen. Wrap it in quotes and JavaScript treats it as plain text, showing it exactly as written — letters, spaces, punctuation and all.

The name is two words with a dot between them, and both halves mean something. console is the panel your words come out on. log is what you are asking it to do there: write this down. You will type the pair together more times than you can count, so it is worth reading it once as two ideas rather than as one long word.

Two smaller things are part of the line rather than decoration:

  • The quotes are what make text. "Priya" is a name spelled out; Priya with no quotes around it would be something JavaScript goes off looking for.
  • The semicolon on the end says that instruction is finished. JavaScript will often work that out on its own from the line break, but every instruction in this editor ends with one, and the habit costs nothing.

A worked example

Here is a different program, so the one in the editor stays yours to finish:

JavaScript
console.log("step 1: fill the kettle");
console.log("step 2: wait");
console.log("step 3: pour");

Running that prints three lines:

Output
step 1: fill the kettle
step 2: wait
step 3: pour

Three calls to console.log, three lines of output, in the order they were written. Each call starts a new line of its own — you never have to ask for one. Notice too that the numbers, the colons and the spaces come out exactly as they were typed. JavaScript did not tidy anything up or add anything of its own.

Your turn

The editor already holds a working program. Press Run before you change anything and you will see a banner: a row of = signs, two lines of text, then another row of = signs.

One thing is wrong with it. The second line says YOUR NAME where your name belongs.

Type your own name over those two words, keep the quotes exactly where they are, and press Run again.

That is the whole task. You are not expected to write a line from scratch yet.

If something goes wrong

If JavaScript complains, it is almost always the quotes. The text you want on screen has to sit between them. "Hello, Ravi!" works; Hello, Ravi! on its own does not, and you get a SyntaxError about a bracket, because JavaScript was trying to read your name as part of an instruction and the sentence stopped making sense.

The other likely slip is a capital letter. Console.log is not console.log, and JavaScript says so plainly: ReferenceError: Console is not defined. It means it looked for something by that name and found nothing.

Nothing you do here can break anything. Your code stays in this browser, so a half-finished attempt is still here if you come back to it, and nothing is sent anywhere. Change it, run it, change it again.

Write your code

Runs in your browser. Press Run (or Ctrl/Cmd+Enter) and the output is checked for you.

Ctrl/Cmd+Enter to run

Press Esc then Tab to move keyboard focus out of the code editor.

Ready
Output will appear here after you run your code.

The runtime is starting in the background. You can type now — it will be ready before you are.

The answer appears here once you have run your code at least once.

Things that often go wrong here

Deleting the quotes along with the placeholder
Quotes are what make something text. Without them the line reads as an instruction rather than as words, and JavaScript stops before anything runs with a SyntaxError saying it was expecting the bracket to close.
Typing Console.log with a capital C
Capital letters matter in JavaScript. Console and console are two different names, so it goes looking for one that does not exist and stops with a ReferenceError saying Console is not defined.
Changing one of the rows of equals signs
Those two rows are the top and bottom of the banner and are already finished. Only the second line has a placeholder in it; if the border stops matching, the banner looks lopsided.
Expecting the missing semicolon to break it
Leave a semicolon off and the program usually still runs, because JavaScript quietly decides the instruction ended at the line break. It is not always that generous, so the semicolons here are worth keeping.

Want a blank editor instead? Open the JavaScript playground.