Priya hosts a board game night every month, and in this course you’ll build a page for it. You’ll write a script that fills in who’s coming and which games are on the table.
If you know JavaScript but have only ever run it in a terminal, or you’ve built the Python side of a web app and never the browser side, this is where you start. You won’t need a framework, and the course assumes no experience with HTML, CSS, or browser tools.
The first tool is one you already have. In this lesson, you’ll open the browser’s Console, try JavaScript one line at a time, and read the browser’s responses, including the ones in red. Start by opening a Console on a tab with nothing in it.
Open the Console on a Blank Tab
To try a line of JavaScript in the browser, you need a place to type it. Chrome and Edge both have a Console built in. You’ll need a current version of either. This course quotes Chrome’s wording, and Edge shows the same.
Keep the browser next to this lesson and type each line as you read. Text lessons like this one are for typing along. The videos show steps where things move, each section ends with an exercise, and the course ends with Priya’s page as a project.
Begin with an empty page in a new tab, so this lesson stays open in its own. Open a new tab with Ctrl+T, or Cmd+T on macOS. Then type about:blank in its address bar and press Enter. The tab goes white, because about:blank is the browser’s built-in empty page, with no website behind it. Then open the Console with the shortcut for your system:
A panel opens beside or below the page. This is DevTools, short for developer tools, a set of panels for looking inside the page. The shortcut lands you on its Console panel.
F12 opens DevTools too, on whichever panel you used last, so you may need to click Console at the top. On many laptops, F12 works only while you hold Fn.
The blue > under the Console’s toolbar is the prompt, where you type. It moves down as lines pile up, and it always sits after the last one. If you’ve used Python’s REPL or Node’s, the Console is the browser’s version: you type a line, press Enter, and the browser runs it and shows the result.
You started on a blank tab because on a busy site, the Console often shows red and yellow lines before you’ve typed anything. Those are the site’s own errors and warnings, from its scripts or from the browser loading it. They have nothing to do with what you typed, so you can leave them alone. On about:blank, the Console starts empty, so every line in it is one you caused.
Before you type, know that if you paste code into the Console, Chrome may stop you with a warning and ask you to type allow pasting first. That guard protects people who are tricked into pasting code they don’t understand. In this course, type the lines yourself, which also helps you remember them.
Read What the Console Echoes
Every line you run gets an answer underneath it, and reading that answer is how you find out what JavaScript made of your line. Priya has five games on this month’s list: Catan takes 90 minutes, Ticket to Ride 60, Codenames 15, Carcassonne 45, and Azul 40. Could they all fit into one evening? Type their playing times as one sum and press Enter:
> 90 + 60 + 15 + 45 + 40
250
The line below your input is the echo: the value your line produced. Chrome marks it with a small arrow pointing back at your line. You may also have seen a gray 250 appear while you were still typing. Chrome works out a preview of the result as you type, and Enter runs the line for real.
That’s 250 minutes, over four hours of games. Rather than retype the sum to try a shorter list, press Up. The Console brings back your earlier lines, newest first. Delete 90 + to drop Catan, then press Enter:
> 60 + 15 + 45 + 40
160
Without Catan, the games fit in under three hours. Most of the time, you’ll use the Console this way, trying a line, reading the echo, adjusting your input, and trying again.
When what you’ve typed is a complete line, Enter runs it. If the line is unfinished, such as 60 + with nothing after it, Chrome starts a new line instead so you can finish it. To spread a longer line over two on purpose, press Shift+Enter, which always starts a new line without running anything:
> 60 + 15
… + 45 + 40
160
This lesson marks the second line with .... In Chrome, both lines sit together after one >, and Enter runs them as one.
Text works the same way, as long as you type it in quotes. Here’s a game’s name with quotes, and then without:
> "Codenames"
'Codenames'
> Codenames
Uncaught ReferenceError: Codenames is not defined
The echo keeps quotes around a string. Chrome shows single quotes, which mean the same as double quotes in JavaScript. A spreadsheet cell treats a bare word as text, but JavaScript doesn’t.
Without quotes, it looks the word up as a name, like a constant declared with const. Nothing called Codenames exists in this tab, so you get a ReferenceError. That red line is only the Console’s answer to that one line, so nothing needs reloading. Type your next line and carry on.
If you’d like more practice reading echoes, the button below opens a chat with the mentor, RealJS’s AI tutor, and asks it for lines to predict. Expect one line at a time, with your guess checked before the answer:
Spot What the Console Won’t Tell You
A red line is the Console telling you something went wrong, but some mistakes don’t get one. Last year, Priya’s group played 1,200 minutes of games. Before typing anything, estimate: at 60 minutes an hour, that’s about 20 hours. Now type it the spreadsheet way, with its comma, and compare:
> 1,200 / 60
3.3333333333333335
> 1200 / 60
20
The first echo is nowhere near your estimate of 20 hours, and no red line warns you. In code, a comma separates two expressions, and the Console echoes the last, so the first line works out 200 / 60. Write a number like this one as 1200, and use a dot for decimals, as in 21.75. Before you trust an echo, estimate what it should be.
For practice at catching an echo like that, the button below asks the mentor for one short calculation to estimate, run, explain, and correct:
The Console doesn’t keep your results after a reload, either. Reload the tab with Ctrl+R, or Cmd+R on macOS, and by default the panel is empty again. If the old lines stay, uncheck Preserve log in Console settings, under the gear icon at the top right of the panel.
Press Up, though, and your earlier lines come back. The browser keeps a history of what you typed, but the results are gone. To empty the panel without reloading, click Clear console, the circle with a line through it at the top left.
Sums like these and edits to what a page shows don’t change the real website for anyone else. They stay in your tab, and a reload brings the original back. Console code runs as part of the page, though, so it can do anything the page’s own scripts can do for you, such as saving data in your browser or sending changes to the site as your logged-in account. That’s why Chrome asks before you paste, and why you should run only lines you understand.
You’ve worked out a few game night sums, read echoes of numbers and text, seen a red error, and caught a wrong answer that came with no error at all. To keep your work outside the Console, you need to put it in a file. In the next video, Run Your First Page and Script, you’ll give Priya’s page its first files and watch a script’s output arrive in this same Console.
You’ll work in VS Code, in a js-course folder with a scratch folder inside it for practice files, so have VS Code ready when you start.