Lesson 1 of 8

Read the error message

Goal

The message tells you where to look

01

Explanation

An error message isn't a punishment. It's a report meant to help you, and it tells you three things: the type of error, what happened, and where it happened.

The message TypeError: Cannot read properties of null (reading 'textContent') means you tried to read a property of null. When that null comes from querySelector, the cause is usually a selector that doesn't match any element: a typo, a dot where you needed #, or a script that runs before the element exists.

The code below has mistakes of exactly this kind, and the console next to it tells you where they are.

02

Your task

Run the code and read what the console says, then fix the mistakes until the page works without any errors.

Checks

4 checks
  1. The heading is selected by its id, not its tag name
  2. The button is selected by its class
  3. Clicking writes the result without an error
  4. The text comes from the right element
03

Hints

0/3
Track lessons0 of 8 done

Learn how to read an error message, check inputs before you use them, and catch the errors worth handling.

Intermediate level, 8 lessons, 1.5 hours in total.

index.html
Preview
index.html100%
–/4

Press “Run and check” to grade your code.

4 checks listed under “Your task”.

Track lessons0 of 8 done

Learn how to read an error message, check inputs before you use them, and catch the errors worth handling.

Intermediate level, 8 lessons, 1.5 hours in total.