Codiqo

Learn JavaScript · lesson 1 of 60 · about 4 minutes

Hello, JavaScript

Change a real web page with your first line of JavaScript, and leave yourself messages in the console.

What you'll learn

  • Change the text on a web page
  • Write text as a string in quotes
  • Show a message with console.log()

Make the page talk

This page says *Hello, stranger!* You want it to greet you instead. Every website you use changes like this: JavaScript runs inside the page and rewrites it.

document.querySelector("#greeting") finds the part of the page whose id is greeting. Setting its .textContent replaces the text inside it.

One line, and the heading changes

document.querySelector("#greeting").textContent = "Hello, Ada!";

Text goes in quotes

"The page is ready" is a string: a piece of text in quotes. Double quotes and single quotes both work, but a string has to end with the same quote it started with.

The quotes aren't part of the text. They only show JavaScript where the text starts and ends.

console.log() shows a message to you, the programmer, in the browser's console

console.log("The page is ready");

Output

The page is ready

Tip

JavaScript is case-sensitive: console.log works, but Console.log is an error. The same goes for textContent and querySelector.

Now try it yourself

This lesson is free in Codiqo, with 5 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.