0Pricing
JavaScript Academy · Lesson

First Program & I/O (console, alerts in browser)

Write your first small programs and practice I/O: console output in any runtime and alerts in the browser.

First Program & I/O (console, alerts in browser) is a free JavaScript Academy lesson on CoddyKit — lesson 3 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro

Goal: Print messages clearly and safely. You'll use console.log everywhere and alert in the browser.

  • Tiny program
  • Console basics
  • Alert with fallback

First console output

Create a simple function, call it, and print the result with console.log.

// A tiny first program
function hello(name) {
  return "Hello, " + name + "!";
}

const message = hello("Coder");
console.log(message);

Readable console logs

Short, labeled lines are easier to scan on small screens.

// Keep logs short and labeled for mobile
const level = 1;
const user = "Ayla";

console.log("User:", user);
console.log("Level:", level);

Pure function + output

Pure functions return values without side effects; perfect for simple prints.

// Pure function: predictable output
function add(a, b) {
  return a + b;
}

const total = add(2, 3);
console.log("Total:", total);

Alert with fallback

alert is browser-only; always provide a console.log fallback.

// Use alert in browsers; fall back to console elsewhere
const text = "Welcome to JavaScript!";
const canAlert = typeof alert === "function";

if (canAlert) {
  alert(text);
} else {
  console.log(text);
}

I/O tips

Tips:

  • Prefer one value per line.
  • Use clear labels like "Total:".
  • Check features before calling browser APIs.

Cross-runtime output quiz

Quick check: Cross-runtime output.

Recap

Recap: You wrote tiny programs, printed readable logs, and used alert with a safe fallback to support any runtime.

Frequently asked questions

Is the “First Program & I/O (console, alerts in browser)” lesson free?

Yes — the full text of “First Program & I/O (console, alerts in browser)” is free to read here on the web, and the JavaScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “First Program & I/O (console, alerts in browser)”?

Write your first small programs and practice I/O: console output in any runtime and alerts in the browser. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start JavaScript Academy?

No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “First Program & I/O (console, alerts in browser)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this JavaScript Academy lesson?

Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What is JavaScript? Engines (V8/SpiderMonkey) & Runtimes (Browser vs Node)
  2. Setup: Node + npm, Running .js, DevTools Console
  3. First Program & I/O (console, alerts in browser)
← Back to JavaScript Academy