Understand what JavaScript is, where it runs, how to connect it to your HTML pages, and how to use the browser console for debugging and experimentation.
JavaScript (JS) is the behavior layer of the web. It adds interactivity, logic, and dynamic changes to HTML and CSS.
| Layer | Language | Purpose |
|---|---|---|
| Structure | HTML | Defines content |
| Style | CSS | Defines appearance |
| Behavior | JavaScript | Defines interaction |
Use the same portfolio project folder from your HTML & CSS course.
portfolio-site/
βββ index.html
βββ about.html
βββ projects.html
βββ contact.html
βββ css/
β βββ style.css
βββ js/
βββ app.js/js folder yet, create one.Open index.html and link your JavaScript file before the closing </body> tag:
<script src="js/app.js" defer></script>
</body>
</html>defer?defer for external scripts.In js/app.js, type this:
// app.js
console.log("Hello, StreetGeek!");
document.title = "StreetGeek Portfolio | JavaScript Active";Open your page β press F12 β Console tab β youβll see your message logged.
The browser console is your developer command line.
console.log("I love JavaScript!");
console.warn("This is a warning!");
console.error("Oops, an error happened!");Basic building blocks:
// Single-line comment
/* Multi-line
comment */
let user = "Yogi";
console.log(`Welcome, ${user}!`);User β user.<script> tag.// app.js
let name = "Yogi";
console.log(`Welcome to StreetGeek, ${name}!`);Now, change the text content of an element dynamically.
<h1 id="hero-title">Welcome!</h1>const heroTitle = document.getElementById("hero-title");
heroTitle.textContent = "Welcome to My Interactive Portfolio π";<footer>
<p>© <span id="year"></span> StreetGeek Academy</p>
</footer>const yearSpan = document.getElementById("year");
yearSpan.textContent = new Date().getFullYear();1) What attribute should you use on your <script> tag to ensure it runs after the HTML loads?
2) Which console method displays errors?
3) Whatβs the difference between HTML, CSS, and JavaScript in a website?
4) Why is document.getElementById() useful?
5) What will this output in the console?
let city = "Richmond";
console.log(`I live in ${city}.`);<p id="greeting"></p>const greeting = document.getElementById("greeting");
const hour = new Date().getHours();
if (hour < 12) {
greeting.textContent = "Good morning βοΈ, welcome to StreetGeek!";
} else if (hour < 18) {
greeting.textContent = "Good afternoon π€οΈ, keep coding!";
} else {
greeting.textContent = "Good evening π, time to build something great!";
}Refresh β your greeting changes automatically based on the time of day.
Next up β MODULE 2: Variables, Data Types & Operators