Learn JavaScript: Part 2
Guide: How to Learn JavaScript as a Beginner: A Simple PlanThe follow-up to Learn JavaScript, in 8 short lessons. Now your code works on a real web page: you change text and style, react to clicks, make a counter, read what a visitor types, add items to a list and switch a class on and off. The page is shown next to your code, so you see the result at once.
0 of 8 lessons done. Your progress is saved in this browser.
1. Change the text of the page
Your code can change the page it runs on. document is the page. document.getElementById("title") finds the element with id="title". .textContent is its text, and you can give it a new value.
Press Run to see the result in the page on the right.
Your task: Change the text of the heading with id="title" to something else.
The page (HTML)
<h1 id="title">Hello</h1>
The page on screen. Try it yourself.
Your code runs in your browser, in a frame that cannot reach this page or the internet. It is not saved or sent anywhere.
Features
- 8 short lessons on changing a web page with JavaScript
- A live page next to your code that you can click and try
- Check my answer, a hint and the full answer for every lesson
- Your progress is remembered in this browser
How to use Learn JavaScript: Part 2
- Read the lesson and the task.
- Write your code and press Run to see the page change.
- Press Check my answer. Use the hint or the answer if you are stuck.
- Go to the next lesson.
Frequently asked questions
Should I do Learn JavaScript first?
Yes, that helps. This part uses variables, if and functions from the first course, and a little HTML. The first course teaches those in 8 lessons.
Is it safe to run my code here?
Your code runs on a small page in a separate frame that cannot reach this site or the internet. Code that runs longer than 2 seconds is not run on the page.
How is my answer checked?
The course runs your code on a hidden copy of the page, clicks the buttons and types in the fields as the task needs, and looks at what the page shows afterwards. So it checks what your code does, not how it is written.
Is my code saved?
Only which lessons you finished is saved, in this browser. The code you type is not stored or sent anywhere.