Your First Complete JavaScript Program
You'll learn: How to combine input, logic, and output into one working program that shows JavaScript in action from start to finish.
What Makes a Program "Complete"?
A complete program isn't just code that runs—it takes something in (input), thinks about it (logic), and gives something back (output). Think of it like a vending machine: you insert coins (input), it checks if you paid enough (logic), and dispenses your snack (output).
Your First Program: A Simple Greeter
Here's a program that asks for your name and greets you:
// Input: Get information from the user
const userName = "Alex"; // We'll use a simple variable for now
// Logic: Create a personalized message
const greeting = "Hello, " + userName + "! Welcome to JavaScript.";
// Output: Show the result
console.log(greeting);
When you run this, you'll see:
Hello, Alex! Welcome to JavaScript.
Breaking It Down
- Input: We store "Alex" in a variable called
userName - Logic: We combine text pieces to build a custom message
- Output:
console.log()displays our result
You can run this in your browser console, Node.js, or any playground you've set up. Try changing "Alex" to your own name and watch the output change!
Why This Matters
This simple program demonstrates the fundamental pattern behind all software: receive information, process it, return a result. Whether you're building a calculator, a game, or a website, you'll follow this same input → logic → output flow.
Key Takeaway: A complete JavaScript program combines three elements: getting data (input), making decisions or transformations (logic), and displaying results (output).