JavaScript
You’ve built the structure. You’ve designed the interface. Now give your webpage behavior and make it respond to the user.
button.addEventListener(“click”, () => {
launch();
});
You’ve Made It to JavaScript.
Everything you’ve learned has been leading here. You know how to create webpage structure with HTML and control its appearance with CSS. Now you’ll add the third major piece of front-end web development: behavior.
>_ The Three Layers of a Webpage
HTML, CSS, and JavaScript have different jobs, but they work together to create the webpages you use every day.
HTML
Provides the content and structure of the webpage.
CSS
Controls the appearance, layout, colors, spacing, and design.
JavaScript
Adds behavior, logic, interaction, and dynamic changes.
>_ What Is JavaScript?
JavaScript is a programming language used extensively on the web. In the browser, it can respond to user actions and change a webpage while the visitor is using it.
Store Information
Variables let JavaScript remember values that your program can use.
Run Instructions
Functions group instructions that can be executed when needed.
React to Users
Events let code respond to actions such as clicks and keyboard input.
Change the Page
JavaScript can find HTML elements and update their content or styles.
>_ Your First JavaScript
One of the simplest ways to see JavaScript working is to send a message to the browser’s developer console.
That one line tells the browser to output the message Hello, JavaScript! to its console.
>_ Variables
A variable gives a value a name so your program can use it later.
const
Declares a variable whose binding won’t be reassigned later.
message
The name we’ve chosen for the variable.
=
Assigns the value on the right to the variable on the left.
"..."
Text surrounded by quotes is called a string.
>_ Connecting JavaScript to HTML
JavaScript becomes especially useful when it interacts with the HTML elements you’ve already learned to create.
Imagine this button:
Launch 🚀
</button>
The button’s id gives JavaScript a way to find that exact HTML element.
>_ Finding an Element
JavaScript can use document.getElementById()
to find an HTML element by its ID.
document.getElementById(“launchButton”);
HTML creates the element. The
id identifies it.
JavaScript finds it. Now your code
can interact with it.
>_ Listening for a Click
An event is something that happens in the browser. Clicking a button is one example.
console.log(“Button clicked!”);
});
The browser is now essentially being told: “When this button is clicked, run this code.”
>_ Changing the Webpage
Instead of only writing to the console, JavaScript can change what the visitor sees.
“Your webpage is alive! ⚡”;
The textContent property changes the
text inside the selected HTML element.
>_ The Interaction Flow
This lesson is an introduction, not the entire JavaScript language. Focus on understanding the pattern: find something → listen for something → do something.
Make the Launch Button Work
The HTML and CSS are ready. Your final mission is to write the JavaScript that makes the interface respond when the Launch button is clicked.
-
✓
Find
launchButtonusingdocument.getElementById(). -
✓
Find the
messageelement and store it in a variable. -
✓
Listen for the button’s
clickevent. -
✓
Change the message to
Your webpage is alive! ⚡. - ✓ Change the button text after the click so the user can see that something happened.
Bring the Webpage to Life
What You’ve Learned
getElementById() can
find an HTML element.
addEventListener() lets
JavaScript respond to user actions.
textContent can change
text displayed on the webpage.
Look How Far You’ve Come. 🎉
You started with a simple Hello, World! and finished by building a webpage that responds to the person using it. Along the way, you learned the foundation behind modern front-end web development. This isn’t the end of learning to code — it’s the point where the possibilities get much bigger.


