Learn basic code by picking one language, writing and running tiny programs for 20–30 minutes a day, and reading the error messages instead of avoiding them. That loop—write, run, break, fix—teaches more in four weeks than months of passive video watching. It fits anyone starting from zero who can commit to short, regular practice sessions.
Choose one language and one free browser-based editor, then work through the same five building blocks in every session: variables, conditionals, loops, functions, and lists. The method below assumes no prior experience and uses Python because its syntax is plain English and it runs without setup. If you already know you want to build websites, swap in JavaScript and use the browser console instead; the steps are the same.
Pick One Language and One Editor Before Writing a Line
Most beginners stall because they keep switching tools. Decide once, then stay for at least four weeks.
- Python — best if you want to automate small tasks, read data, or learn general programming concepts. Runs in any browser editor or as a free desktop install.
- JavaScript — best if your goal is websites or you want to see results in a browser immediately. No install needed; open the browser developer console.
- HTML and CSS — not programming languages in the loop-and-variable sense, but the right first step if you only want to build a page. Learn these for two weeks, then add JavaScript.
For an editor, use any free browser-based code playground that lets you press Run and see output. If you install Python on your computer, use the editor that comes with it or any plain text editor; save files with a .py ending. Menu labels differ by version, so look for File > New File and a Run or Execute button rather than memorising exact wording.
The Five Building Blocks in the Order They Click
Every language has the same core ideas. Learn them in this order because each one depends on the last.
- Variables — a named box that holds a value. In Python:
age = 30. In JavaScript:let age = 30;. Practise storing a number, a word, and a true/false value. - Conditionals — code that chooses. Write an
ifstatement that prints one message when a number is above 10 and another when it is not. Run it with three different numbers. - Loops — code that repeats. Write a loop that prints the numbers 1 to 5. Then change it to print only even numbers.
- Functions — a named block you can reuse. Write a function that takes two numbers and returns their sum. Call it three times with different inputs.
- Lists — an ordered collection. Make a list of five words, print the first one, then print each one on its own line with a loop.
Spend one day on each block, then two days combining them into a single small program such as a tip calculator or a quiz that asks three questions. Combining is where the ideas stick.
What Goes Wrong in Week One and the Fix for Each
| Symptom | Likely cause | Fix |
|---|---|---|
| Code runs but prints nothing | No print or output statement, or the code is inside a function that is never called | Add a print line at the end and call the function by name |
| SyntaxError on a line that looks fine | Missing colon, bracket, or quote mark; Python is strict about indentation | Check the line above the error first; most syntax errors are caused there |
| Program stops with NameError | A variable is used before it is defined, or the name is misspelled | Define the variable above the line that uses it; names are case-sensitive |
| Loop never ends | The condition never becomes false, or the counter is not updated inside the loop | Add or fix the line that changes the counter each pass |
| Output is the wrong type | Text and numbers are mixed; "5" + 3 fails where 5 + 3 works | Convert with int() or str() before combining |
Read every error message from the bottom up. The last line names the error type; the line above it gives the file and line number. Copy the error text into a search engine—most beginner errors have been answered thousands of times.
A Four-Week Schedule That Fits Around a Job
Twenty-five minutes a day, five days a week, is enough to reach a working grasp of the basics. The schedule below uses Python; substitute JavaScript syntax if that is your choice.
- Days 1–5: Variables and printing. Write five programs that store a name, an age, and a favourite number, then print a sentence using each. Aim for 10 lines per program.
- Days 6–10: Conditionals. Write a program that grades a score: below 50 prints one message, 50–79 another, 80 and above a third. Test all three branches.
- Days 11–15: Loops. Print a 5×5 grid of asterisks using two nested loops. Then write a loop that adds the numbers 1 to 100 and prints the total (5050).
- Days 16–20: Functions. Turn the grading program into a function that takes a score and returns a grade. Call it with five different scores.
- Days 21–25: Lists. Store ten words in a list, print them in reverse, then print only the ones longer than four letters.
- Days 26–30: One combined project. Build a number-guessing game: the program picks a number between 1 and 20, the user guesses, and the program says higher or lower until correct. This uses every block above.
If a day is missed, do not double up; continue where the schedule left off. Consistency matters more than total hours.
How to Know You Have the Basics
You have the basics when you can read a 30-line program you did not write and explain what each line does, and when you can write a small program from a blank file without copying. A practical test: build a program that asks for ten numbers, stores them in a list, and prints the average, the largest, and the smallest. If you can do that in under 30 minutes with the help of a search engine for syntax only, you are ready to move on to files, dictionaries, or a framework.
Keep every program you write in one folder. Re-reading your own early code a week later shows what you have learned faster than any tutorial. When you get stuck for more than 15 minutes, write down the exact error and the line it points to, then search that text; if nothing helps, simplify the program by deleting half the lines and running it again to find the broken part.