1.A program — precise instructions for a computer
A program is a set of instructions that lists, in order, what a computer should do. It is a lot like a recipe, with one big difference. When a recipe says "a pinch of salt," a person makes a reasonable guess, but a computer never guesses. It does exactly what is written, in exactly the order it is written. So writing a program means spelling out every part you would normally leave as "they'll figure it out."
This refusal to guess is both a weakness and a strength. If an instruction is even slightly wrong, you get a strange result, but if the instructions are right, the computer carries them out a hundred times or a million times, identically, tirelessly, and quickly. Adding up the same column in a spreadsheet every month, renaming files one by one, or fixing the phone-number format in hundreds of lines of text: the work that is boring and error-prone for people is exactly what programs do well.
These days you can ask an AI coding assistant in plain words and it will write the code for you. That does not make the basics of coding unnecessary. To judge whether the code an AI wrote really does what you wanted, and whether it misses any cases, you need to be able to read code. The goal of this course is not to make you a professional developer but to help you write simple code yourself and read and check code written by others (or by AI) (Lesson 10).
2.Algorithmic thinking — breaking things into sequence, choice, and repetition
A set of steps that solves a problem is called an algorithm. The name sounds grand, but we use algorithms every day. How you get out of the house in the morning, the order in which you do your shopping, and how you grade a test are all algorithms. Learning to program is partly practice at taking the things you do naturally in your head and writing them down one step at a time.
Remarkably, almost every algorithm is made from just three ingredients. The first is sequence: doing things one after another, from top to bottom. The second is choice (a condition): branching depending on the situation, as in "if this, do that; otherwise, do something else" (Lesson 3). The third is repetition: doing the same thing a set number of times or until some condition is met (Lesson 4). If you can combine these three freely, you can turn most tasks into instructions.
The trick when breaking a task down is to ask, "Could someone seeing this step for the first time follow it exactly?" "Grade the test" is too big. Break it into "compare the first answer with the correct answer, add 1 to the score if they match, move on to the next answer, repeat until the last answer," and the sequence, choice, and repetition finally become visible. The structure that appears this way becomes the skeleton of your code.
| Ingredient | Meaning | Everyday example | Lesson |
|---|---|---|---|
| Sequence | Do things in order, top to bottom | Boil water → add noodles → wait 3 minutes | Lesson 1 |
| Choice | Do different things depending on the situation | If it is raining, take an umbrella; otherwise, just go out | Lesson 3 |
| Repetition | Do the same thing several times | Grade the answer sheet one question at a time until the end | Lesson 4 |
- Step 1 Prepare (sequence): set the absence count to 0 and start with the first student on the list.
- Step 2 Check (choice): if the current student is not present, add 1 to the absence count. If they are present, do nothing.
- Step 3 Move on (repetition): go to the next student and repeat Step 2. Stop after checking the last student on the list.
- Step 4 Result (sequence): report the absence count.
- Check: if all 30 are present, the count stays at the starting value of 0; if all are absent, it becomes 30. If both extreme cases come out right, you can trust the steps.
3.Input → processing → output
Seen from the outside, an algorithm always has the same shape. It takes something in (input), does something with it (processing), and hands back a result (output). A calculator takes numbers and an operation, calculates, and shows the answer on screen; a spell checker takes text, finds mistakes, and marks them. When you first write code, filling in these three boxes first makes it much clearer what you need to build.
Being clear about the input matters most. "Calculate the price" leaves out what you receive. "Take a product's price and quantity and compute the total" makes it clear that there are two inputs and that both are numbers. Questions such as "What if the quantity is 0?" or "What if the price comes in negative?" then follow naturally. The habit of asking these questions up front leads directly to edge values in Lesson 3 and to checking AI code in Lesson 10.
In this course's playground you will mostly print results with console.log. Once you learn functions in Lesson 5, you will move on to taking input as "parameters" and handing back output as a "return value." The form changes, but the input, processing, and output framework stays the same.
| Task | Input | Processing | Output |
|---|---|---|---|
| Shopping total | Item prices | Add them all up | Total amount |
| Average score | List of scores | Add them, then divide by the count | Average |
| Character count | Text | Count the characters one by one | Number of characters |
| Pass or fail | Score | Compare with the pass mark | Pass or fail |
4.Your first code — JavaScript and `console.log`
This course uses JavaScript. Every web browser has a JavaScript engine built in, so you can run it right away without installing anything. It started as the language that makes web pages interactive, but today it is also widely used on servers, in automation scripts, in spreadsheet add-ons, and more. The ideas you learn here, such as sequence, choice, repetition, and functions, carry over almost unchanged to other languages.
The first command to learn is console.log. It shows whatever you put inside the parentheses as one line in the output area. Text (a string) is wrapped in double or single quotes, and numbers are written as they are. If you put several values separated by commas, they are shown on one line with a space between them. If you put in an expression, you get the calculated result.
Code runs one line at a time, from top to bottom. So if you write three console.log lines, you get three lines of output in the same order. This is the simplest way that sequence, the first ingredient of an algorithm, shows up in code. Copy the code below into the playground and run it, then change the numbers and text to see how the output changes.
console.log("Hello");
console.log("This is Coding Basics");
console.log(2026);Hello This is Coding Basics 2026
console.log("Price of 3 apples:", 1200 * 3);
console.log("10 divided by 4 =", 10 / 4);
console.log("Name", "Alex", "Age", 20);Price of 3 apples: 3600 10 divided by 4 = 2.5 Name Alex Age 20
console.log.5.Statements, comments, and reading your first error
Each line of code is called a statement, and in JavaScript it is customary to end a statement with a semicolon (;). If you leave it out, JavaScript usually copes, but in rare cases the code gets interpreted differently from what you meant, so this course always includes it. Text after // is a comment and is not run. A comment is a note left for people to read; writing down why you did something helps your future self and your coworkers (and AI) understand the code.
Because the computer never guesses, a single wrong letter stops it. For example, if you mistype console as consol, you get an error saying that name is not defined. Red error messages are intimidating at first, but an error is a helpful notice that tells you where the computer stopped and why. A message usually contains the type of error, a short description, and a line number.
In the example below, the first line prints normally and the program stops at the second line. Notice also that the lines after the error do not run. The wording of error messages can differ slightly between browsers, but the type of error (here, ReferenceError) and the line number give you the same information. Lesson 8 covers how to read each type of error in detail.
// Comments are not run
console.log("First line"); // you can add one at the end of a line
console.log("Second line");First line Second line
console.log("This line runs");
consol.log("A line with a typo");
console.log("This line never runs");This line runs
ReferenceError: consol is not defined- Read the error message to the end: look at the type (
ReferenceErrorand so on), then the description, then the line number - Look at the line the number points to and the line just above it: a missing bracket or quote can start on the previous line
- Fix one thing at a time and run again: if you change several places at once, you cannot tell which change made the difference
- Check spelling and capitalization: JavaScript treats
Consoleandconsoleas different names
6.How to use the playground
At the bottom of each lesson there is a code playground. The starting code describes what to do in comments; fill in the blanks and run it to see the output, and press Grade to compare it with the expected result. If you get stuck, look at the hint first, and if it is still hard, look at the sample solution. But do not just copy it: check line by line why it was written that way, then delete it and write it again yourself. That is the fastest way to improve.
Code in the playground runs only inside your own browser, in a safe space isolated from other pages (a sandbox), and is never sent to a server. That is why code that changes the screen or connects to the internet does not work in the playground; only printing with console.log does. Even if you accidentally write a loop that never ends, it is stopped automatically after a few seconds, so feel free to experiment.
Do not be afraid to change anything in the playground. Change numbers, reorder lines, or make a typo on purpose and see how the error message changes. You do not get better at coding just by reading; you get better by running code yourself and getting things wrong.
📌 Key points
- A program is a precise set of instructions that a computer follows exactly, without guessing
- Almost every algorithm is a combination of three ingredients: sequence, choice, and repetition
- When breaking down a task, make the steps small enough that someone seeing them for the first time could follow them exactly
- Splitting any task into input, processing, and output makes it clear what to build
- Print values with
console.log, and read error messages in the order type, description, line number
🧪 Code lab
Practice matching the expected output using only console.log. Your output is compared with the expected output line by line.
Your code runs only inside an isolated sandbox in this browser and is never sent to a server. It has no network access and is stopped after 2 seconds. Edited code is saved only in this browser. Ctrl+Enter (⌘+Enter) runs it; Tab inserts two spaces (press Esc, then Tab, to move on).
JavaScript is off, so the code can't run here, but you can still read each task, its starter code, the automatic checks and a sample solution.
1Print three lines
Use console.log three times to print these three lines in order: Hello / Coding Basics Lesson 1 / Ready
Hello Coding Basics Lesson 1 Ready
💡 Hint
Wrap text in double quotes and end each line with a semicolon. One console.log per line.
Show a sample solution
console.log("Hello");
console.log("Coding Basics Lesson 1");
console.log("Ready");
2Input → processing → output: a receipt
A hypothetical shopping trip: you bought 2 cartons of milk at 2,500 won each and 1 loaf of bread at 3,000 won. Let the code do the arithmetic and print three lines like this: Milk: 5000 / Bread: 3000 / Total: 8000. Do not type the results directly; use expressions like 2500 * 2.
Milk: 5000 Bread: 3000 Total: 8000
💡 Hint
Two values separated by a comma are joined by one space. Multiplication is *, and it is calculated before addition.
Show a sample solution
// milk 2500 won x 2, bread 3000 won x 1
console.log("Milk:", 2500 * 2);
console.log("Bread:", 3000 * 1);
console.log("Total:", 2500 * 2 + 3000 * 1);
3Put the steps in order
The steps for cooking instant noodles are mixed up. Change only the order of the lines so that steps 1 to 5 are printed in order. Do not change the text.
1. Pour water into a pot 2. Bring the water to a boil 3. Add the noodles and seasoning 4. Wait 3 minutes 5. Serve in a bowl
💡 Hint
Code runs from top to bottom. Move the lines so that what must happen first is at the top.
Show a sample solution
console.log("1. Pour water into a pot");
console.log("2. Bring the water to a boil");
console.log("3. Add the noodles and seasoning");
console.log("4. Wait 3 minutes");
console.log("5. Serve in a bowl");
🤖 Try asking AI like this
Copy a prompt and replace the [ ] parts with your own situation. Don't take the answer on trust — check it against this lesson.
When you want to break an everyday task into an algorithm
Break [description of the task] that I do every week into steps that someone seeing it for the first time could follow exactly. Mark whether each step is sequence, choice, or repetition, and list the inputs and outputs separately. Do not write any code yet, and if there are cases I have missed (for example, when the data is empty), ask me about them.
When you meet an error message for the first time
I have just started learning JavaScript. Explain the error message below in plain words, split into its type, meaning, and line number. Instead of giving me the fixed code right away, first tell me where to look so I can find the problem myself. Code: [paste code] Error: [paste error message]
When you want more practice problems
Make 5 very easy practice problems that can be solved using only JavaScript `console.log`. Write the exact expected output for each one, keep the solution code hidden, and when I send my answer, compare it with the expected output line by line.
🧰 Related tools
Tools for checking and tidying the JSON, regular expressions and text from this lesson. Don't paste real personal data or passwords.
- Quick NotepadUse it as a scratch pad to write out a task as sequence, choice, and repetition steps before you start coding.
- Character CounterSee how a task with a clear input, processing, and output, like counting characters, works in a real tool, and compare the results when you do the same thing in code in Lesson 7.
- Text Diff CheckerPaste your output and the expected output side by side and it highlights the lines that differ, which helps you find which line is wrong.
- MDN Web Docs — JavaScript Guide: grammar and types, and the console documentation
- General material from introductory programming textbooks on algorithms (sequence, selection, iteration) and the input–process–output model
Reached every goal above? Mark the lesson complete.
Storage is unavailable in this browser, so this lasts only for this page.💻 Coding Basics
- 1What Is a Program? — Breaking Work into Sequence, Choice, and Repetition
- 2Values, Variables, and Types — Putting Name Tags on Values
- 3Conditionals — Taking Different Paths Depending on the Situation
- 4Loops — Doing the Same Thing Many Times, Exactly
- 5Functions — Splitting Work into Small Named Machines
- 6Arrays and Objects — Storing and Handling Data
- 7Strings and Text — Cutting, Finding and Replacing Characters
- 8Debugging and Reading Errors — Turning Red Text into Clues
- 9Simple Automation — Spreadsheet Math and Text Cleanup in Code
- 10Reading and Verifying AI-Written Code — Tests, Security, Licenses, Privacy