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.

Lesson 3 of 38 steps

First Program & I/O (console, alerts in browser) is a free JavaScript Academy lesson on CoddyKit. This is lesson 3 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The JavaScript Academy course includes 3 lessons in total.

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.

Free to start

Learn JavaScript with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
59
Lessons
200

Frequently Asked Questions

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

Yes — any 3 lessons of the JavaScript Academy learning path, including “First Program & I/O (console, alerts in browser)”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The JavaScript Academy course includes 3 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 3.

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