Aral Code

JavaScript Tutorial

JavaScript is the programming language of the web. HTML gives a page its structure, CSS makes it look good, and JavaScript makes it do things: check quiz answers, compute a grade, show and hide menus, run a timer, or power a simple game.

This free course has 30 short lessons. Every lesson has examples you can edit and run right on the page, a list of common mistakes, a Taglish summary and a quick quiz. You don't need to install anything: your browser already runs JavaScript.

Before you start

You should know basic HTML and a little CSS. If you have never written a web page, take the HTML Tutorial first, at least up to Class and Id, because JavaScript often finds elements by their id or class.

What you'll be able to do

  • Store information in variables and do math with it
  • Make decisions with if and repeat work with loops
  • Write your own functions and reuse them
  • Work with lists (arrays) and records (objects)
  • Change a web page with the DOM and react to clicks and typing
  • Build a grade calculator, a to-do list and a quiz game

All lessons

Getting Started

  1. Introduction to JavaScriptWhat JavaScript is, what it can do on a web page, and how it works together with HTML and CSS. Write and run your first line of JavaScript.
  2. Where to Put JavaScript — script Tags and External FilesAdd JavaScript inside a script tag in the head or body, or in a separate .js file. Learn why scripts usually go at the end of the body or use defer.
  3. JavaScript Output — console.log, textContent, innerHTML and alertFour ways JavaScript shows results — writing into an element with textContent or innerHTML, printing to the console, alert boxes, and document.write.
  4. JavaScript Syntax, Statements and CommentsThe basic grammar of JavaScript — statements, semicolons, code blocks, case sensitivity, naming rules and comments that explain your code.

Variables & Data

  1. JavaScript Variables — let, const and varStore values in variables with let and const, change them, and learn why modern JavaScript avoids var. Includes a baon budget example.
  2. JavaScript Data Types — Strings, Numbers, Booleans and MoreThe kinds of values JavaScript works with — string, number, boolean, undefined, null, plus arrays and objects — and how to check a type with typeof.
  3. JavaScript Operators — Arithmetic and AssignmentDo math in JavaScript with +, -, *, /, % and **, update variables with +=, -= and ++, and understand the order of operations.
  4. JavaScript Strings and Template LiteralsWork with text in JavaScript — quotes, escape characters, string length, joining text, and template literals with ${} for clean messages.
  5. JavaScript String MethodsUseful string methods — toUpperCase, toLowerCase, trim, includes, startsWith, indexOf, slice, replace, split and padStart — with school and store examples.
  6. JavaScript Numbers and the Math ObjectConvert text to numbers, round money with toFixed, use Math.round, floor, ceil, max, min and Math.random to make dice and random pickers.

Decisions & Loops

  1. JavaScript Comparisons and Logical OperatorsCompare values with ===, !==, >, <, >= and <=, combine conditions with && (and), || (or) and ! (not), and understand truthy and falsy values.
  2. JavaScript if, else and else ifMake your program decide what to do with if, else and else if. Build a DepEd-style grade descriptor and a simple login check, and learn the ternary operator.
  3. JavaScript switch StatementChoose between many exact values with switch, case, break and default — with a day-of-the-week schedule and a sari-sari store menu.
  4. JavaScript for LoopsRepeat code with for loops — count up and down, skip by steps, build multiplication tables, loop through strings and arrays, and use break and continue.
  5. JavaScript while and do…while LoopsRepeat code while a condition is true with while and do…while loops — savings goals, guessing games — and learn how to avoid infinite loops.

Functions

  1. JavaScript FunctionsWrite reusable blocks of code with functions — parameters, arguments, return values and default values — with a grade-average and peso-change calculator.
  2. JavaScript Scope and Arrow FunctionsUnderstand where variables can be used (global, function and block scope), and write short functions with arrow syntax and callbacks.

Arrays & Objects

  1. JavaScript ArraysStore lists of values in arrays — create them, read and change items by index, get the length, add and remove items with push, pop, shift, unshift and splice.
  2. JavaScript Array Methods — forEach, map, filter, find, reduce and sortProcess lists the modern way with forEach, map, filter, find, some, every, reduce and sort, using class grades and store prices as examples.
  3. JavaScript ObjectsGroup related data into objects with properties and methods — read, change, add and delete properties, loop through them, and store a whole class as an array of objects.
  4. JavaScript JSON — Saving and Sharing DataJSON is the standard text format for data on the web. Learn its rules, convert objects to text with JSON.stringify and back with JSON.parse.

The DOM

  1. The JavaScript HTML DOM — Finding ElementsThe DOM is how JavaScript sees your HTML page. Find elements with getElementById, querySelector and querySelectorAll, and understand the page as a tree.
  2. Changing HTML, Styles and Classes with JavaScriptChange text, HTML, attributes, styles and CSS classes with JavaScript, and create, add and remove elements with createElement, append and remove.
  3. JavaScript Events and addEventListenerReact to clicks, typing, mouse movement and key presses with addEventListener. Use the event object, preventDefault and event delegation.
  4. JavaScript Forms and Input ValidationRead values from inputs, selects, checkboxes and radio buttons, validate them with JavaScript, show friendly error messages, and build a BMI calculator.

Going Further

  1. JavaScript DatesWork with dates and times — create Date objects, get the year, month, day and time, format dates in Filipino and English, and compute ages and countdowns.
  2. JavaScript Timers — setTimeout and setIntervalRun code later with setTimeout and repeatedly with setInterval, stop timers with clearInterval, and build a live clock and a quiz countdown.
  3. JavaScript Errors and DebuggingRead error messages, find bugs with console.log and the browser DevTools, and handle problems gracefully with try, catch, finally and throw.
  4. JavaScript ClassesCreate many similar objects from one blueprint with class, constructor and methods, and extend a class with inheritance. Includes a bank-style savings account.
  5. JavaScript Final Project — Build a Quiz GamePut everything together and build a complete quiz game with questions stored in an array of objects, a score, a timer, feedback and a results screen.