018
LVL 01 — WAVE DEFENDER SESSION 018 DAY 18

BUTTONS DO NOTHING

🎫 PIXELCRAFT-008 · Part 1 of 3
🐛 Bug | 🔵 Easy | Priority: 🔴 Critical

All toolbar buttons are visually correct but clicking them has zero effect. The JavaScript file exists but seems broken. Investigation needed.

This is a multi-session ticket. Part 1: investigate the existing code and understand the fundamentals.
CONCEPTS.UNLOCKED
What JavaScript Is
The programming language that makes web pages interactive. HTML = structure, CSS = style, JavaScript = behavior. The third pillar of the web.
🔗
Connecting JS to HTML
<script src="app.js"></script> at the end of <body>, or with the defer attribute. Scripts run in order, and need the DOM to exist before they can manipulate it.
🖥
The Browser Console
console.log(), console.error(), console.warn() — your primary debugging tool. F12 → Console tab. Type JavaScript live and see results instantly.
📦
Variables: let & const
let (value can change), const (value can't change). Always prefer const unless you need to reassign. Avoid var — it's legacy with confusing scope rules.
🧩
Data Types
string ("hello"), number (42), boolean (true/false), null (intentionally empty), undefined (not yet assigned). Check with typeof x.
🔍
Reading Existing Code
Following the logic of an existing JavaScript file. You don't need to understand everything — get the general shape, find patterns, use console.log to trace execution.
HANDS-ON.TASKS
01
Play in the Console

Open the browser console (F12 → Console tab). Type JavaScript live:

2 + 2 // 4 "hello".toUpperCase() // "HELLO" typeof 42 // "number" typeof "hello" // "string"
The console is your JavaScript playground. Every expression is evaluated instantly — no save, no compile, no build step.
02
Read the Existing Code

Open src/scripts/app.js. Read it top to bottom. Don't try to understand everything — get the general shape.

Find errors: the console shows red error messages from PixelCraft's JavaScript. Read them.

03
Learn Variables
const canvasWidth = 1920; const canvasHeight = 1080; let currentFilter = "none"; let brightness = 0; console.log("Canvas size:", canvasWidth, "x", canvasHeight); console.log("Total pixels:", canvasWidth * canvasHeight); console.log("Memory needed:", canvasWidth * canvasHeight * 4, "bytes");

Operators: + (add), - (subtract), * (multiply), / (divide), % (remainder), ** (power)

04
Discover the First Bug

A variable is used before it's declared → ReferenceError

Fix it: move the variable declaration before its first use.

JavaScript reads top to bottom. If you try to use a const or let variable before it's declared, you get a ReferenceError. This is called the "Temporal Dead Zone" — a very real concept you'll encounter again.
05
Trace Execution with console.log

Add console.log statements to trace what runs when the page loads:

console.log("Step 1: Page loaded"); console.log("Step 2: Canvas initialized"); console.log("Step 3: Buttons should be wired..."); // Your logs reveal: Step 3 never prints! // Something breaks before it.
This is the most basic debugging technique: breadcrumb logging. Drop console.logs at key points → see where execution stops → find the bug.
🔄 TICKET STATUS: IN PROGRESS
You've started investigating, found one error, but buttons still don't work. Continues next session.
CS.DEEP-DIVE

Variables are named memory locations.

const width = 1920 tells the computer: "Reserve a spot in RAM, put 1920 there, label it 'width'."

// Different types use different memory:

number  → 8 bytes (64-bit float)
string  → 2 bytes per character (UTF-16)
boolean → theoretically 1 bit

// Understanding this physical reality
// helps you understand why:

const  → the label is locked
          (can't point elsewhere)
let    → the label can be moved
          (can point to new data)

// Later: why some languages (C, C++, Rust)
// require you to manage memory manually.
"Console Detective"
[A] Open 3 popular websites. Open DevTools Console. Look for any errors or warnings. What can you learn about how they built their site?
[B] In the console, create variables for your name, age, and favorite color. Use typeof to check each. Try adding a string to a number — what happens?
[C] Calculate how much memory a 4K image (3840×2160) needs: width × height × 4 bytes (RGBA). Express it in MB.
REF.MATERIAL
ARTICLE
Mozilla Developer Network
The gold-standard JS introduction: variables, data types, operators, and your first script. The companion to the HTML/CSS MDN guides.
JAVASCRIPTMDNBEGINNER
VIDEO
Programming with Mosh
1-hour walkthrough covering variables, types, operators, and the console. Clear explanations with practical examples.
JAVASCRIPTCRASH COURSE
VIDEO
Fireship
The fastest possible overview of JavaScript — history, syntax, event loop, and why it rules the web.
JAVASCRIPTQUICK
BOOK
javascript.info
Interactive textbook covering variables, data types, and operators in depth. Excellent for self-paced learning with runnable code examples.
JAVASCRIPTINTERACTIVE
TOOL
Google Chrome
Official guide to the Console: logging, filtering, live expressions, and debugging. Master your most-used debugging tool.
DEVTOOLSCONSOLE
// LEAVE EXCITED BECAUSE
You wrote JavaScript and it executed instantly. You found a real error in the code by reading the console. Programming is detective work — and you just solved your first clue.