Programming Basics — Logic That Runs the World
What you'll learn
- The building blocks shared by every language: variables, conditions, loops, functions
- How to break a problem into steps a computer can follow
- Write and run real logic, checked instantly
- The foundation everything else in backend builds on
A recipe a computer can follow 📝
Programming is writing a recipe so exact that a machine — which has zero common sense — can follow it perfectly. Every recipe uses the same four ingredients, in every language:
// 1. VARIABLES — remember values
let total = 0;
const taxRate = 0.15;
// 2. CONDITIONS — make decisions
if (total > 100) {
console.log("Big order");
} else {
console.log("Small order");
}
// 3. LOOPS — repeat work
for (let i = 1; i <= 3; i++) {
console.log("Item", i);
}
// 4. FUNCTIONS — package reusable steps
function withTax(price) {
return price + price * 0.15;
}
The skill that matters most isn't memorizing syntax — it's decomposition: taking "calculate the total of a shopping cart with tax" and breaking it into tiny, ordered steps:
- Start total at 0
- For each item, add its price to total
- Multiply total by 1.15 for tax
- Return the result
Once you can decompose a problem into steps, translating it into any language is the easy part.
Apply decomposition. Write a function cartTotal(prices) that takes a list (array) of item prices and returns the total with 15% tax added.
Example: cartTotal([100, 100]) → 230 (200 + 15%).
Write fizzbuzz(n) — the famous interview question. Return:
"FizzBuzz"if n is divisible by both 3 and 5"Fizz"if divisible by 3 only"Buzz"if divisible by 5 only- otherwise the number itself (as a number)
(The trick: check 3-and-5 first.)
Recursion — a function that calls itself 🔁
Loops repeat by going around; recursion repeats by going inward — a function that calls a smaller copy of itself until it reaches a simple case it can answer directly.
Think of Russian nesting dolls: to know how many dolls are in the set, you open the outer doll and ask the same question about the doll inside it — smaller and smaller — until you reach the tiny solid doll that can't open. That smallest doll is the base case: the point where the function stops calling itself and just returns an answer.
function countdown(n) {
if (n <= 0) { // base case — stop here
console.log("Liftoff!");
return;
}
console.log(n);
countdown(n - 1); // recursive case — a smaller version of the same problem
}
Every recursive function needs exactly these two parts:
- Base case — the simplest input, answered directly, with no further call (without this, it calls itself forever and crashes with a "stack overflow").
- Recursive case — the function calls itself with an input that is closer to the base case.
Recursion isn't always the fastest choice, but for problems that are naturally "a small version of the same problem" — like walking nested folders, or summing a list — it's often the clearest way to express the idea. Any loop can be rewritten as recursion, and vice versa; it's a second lens for the same skill you just learned: decomposition.
Write sumRange(n) recursively (no loops!) that returns the sum of all whole numbers from 1 to n.
Example: sumRange(3) → 6 (1 + 2 + 3). Think: what's the base case (smallest n)? What's the recursive case (sumRange(n) in terms of sumRange(n-1))?
Real-world case study: FizzBuzz as an industry filter 🔍
The exercise you just solved earlier in this lesson isn't a toy invented for this course — FizzBuzz is a real, widely-used technical-interview screening question, popularized around 2007 by programmer Imran Ghory and later written about extensively by Jeff Atwood (co-founder of Stack Overflow).
The backstory is blunt: hiring managers at real companies found that a large share of candidates who listed years of "programming experience" on their résumés could not write a program that prints numbers 1 to 100, substituting "Fizz" for multiples of 3 and "Buzz" for multiples of 5. Not because the logic is hard — it's a handful of conditions and a loop — but because some candidates had never truly practiced turning a plain-English rule into working, ordered code (exactly the decomposition skill from this lesson).
FizzBuzz became a standard early-round filter at many companies precisely because it separates "can talk about code" from "can actually write code that runs correctly." It's still used today, sometimes as a live-coding warm-up before a harder problem.
The lesson: the basics in this file — variables, conditions, loops, functions, and decomposing a problem step by step — aren't "beginner filler" to rush past. They are, quite literally, the bar that real companies use to filter candidates before anything else.
Question 1 of 6
What is the most important programming skill?
Question 2 of 6
What does n % 5 === 0 check?
Question 3 of 6
Why must FizzBuzz check divisibility by 3 AND 5 first?
Question 4 of 6
Every recursive function must have a…
Question 5 of 6
In sumRange(n) = n + sumRange(n - 1), what is the recursive case doing?
Question 6 of 6
Why is FizzBuzz used as a real hiring filter?
Summary
- Every language shares 4 blocks: variables, conditions, loops, functions
- The real skill is decomposition — turning problems into ordered steps
- You solved cart-total and FizzBuzz, a genuine interview classic
- Recursion solves problems by calling a smaller version of themselves, with a base case to stop — you wrote a recursive
sumRange - FizzBuzz's real history shows why these fundamentals are an actual hiring filter, not "beginner filler"
Next: Databases & SQL — where backend applications store everything permanently.
Practice
Reading is not learning until you run something. Pick one.