What Is Programming?

A teacher needs a total

A teacher is preparing a student's report. The student scored 40 in maths and 35 in science, with each subject marked out of 50. The teacher needs their combined marks.

Programming means writing instructions that a computer can execute to perform a task. Those instructions form a program. In this lesson, our program will store the two marks, add them and display the total.

You do not need any previous coding knowledge or software installation. Start by understanding the task; the code will make more sense once you know what it should do.

  1. Explain the idea

    Describe programming as a way to turn a clear task into instructions a computer can follow.

  2. Follow the information

    Identify the input marks, explain the addition and predict the displayed total.

  3. Make a useful change

    Adjust the calculation for another subject and recognize when a program runs but produces the wrong answer.

From marks to a report total

  1. Input: subject marks

    Maths: 40 out of 50. Science: 35 out of 50.

  2. Process: add the marks

    Use the two numbers in a calculation: 40 + 35.

  3. Output: total marks

    Display 75 out of a possible 100 marks.

The arrows show how information moves: marks go in, addition happens, and the total comes out.

Programs, code and programming

A program is the set of instructions that performs a task. Code, or source code, is the text used to write those instructions in a programming language. Programming includes understanding the problem, writing that code and checking whether the result is correct.

A programming language has agreed rules for expressing instructions. We will use JavaScript for the small examples on this page. The idea of storing information, calculating with it and displaying a result also applies in languages such as Python, although their written instructions look different.

Think of a program as a carefully written classroom procedure. That comparison helps explain order, but a computer does not interpret an unclear instruction as a teacher might. The program and the tools running it must supply precise operations.

You do not need to learn machine instructions here. The next lesson explains how computers understand code, and the following lesson introduces compilers and interpreters, the language tools involved in running programs.

Why write a program for a simple calculation?

Adding two numbers is easy by hand. Programming becomes more useful when the same clear task must be repeated—for example, preparing reports for an entire class or recalculating them after a mark changes.

A program can automate repeated work, apply the same rule consistently and help people use information. It can also respond to actions: a teacher enters marks, selects a student or requests a report, and the program produces the corresponding result.

Consistency is valuable only when the rule is correct. If the code subtracts science from maths, it can repeat that mistake for every student. The programmer must check the rule, the supplied information and the output.

We will work with one student first. Later, loops repeat work for several values and functions give useful tasks reusable names.

Where is programming used?

School software gives us several familiar examples of programming in action. Each application combines information with instructions, but the inputs and outputs differ.

  • Websites and mobile apps: a school notice page displays announcements, while an attendance app records a teacher's selections.
  • Data analysis: a report program combines marks or summarizes attendance so a teacher can review a class.
  • Games and simulations: a learning game checks an answer, changes a score and displays feedback.
  • Embedded devices: software inside a device can read a clock and trigger a school bell at a configured time. Embedded means the program runs as part of that device.

Programming also supports work outside school, such as online shopping, scientific calculations and transport systems. A different purpose requires different instructions; learning one small example is a starting point, rather than a complete design for all these systems.

Separate input, processing and output

Input is information supplied to a program. Our inputs are the student's maths mark of 40 and science mark of 35. In this first example, we write the numbers directly in the code. A larger application could receive them from a form or a stored record.

Processing is the work done with that information. Our rule is to add maths and science. Output is information the program makes available, such as the combined total of 75 shown to the teacher.

Write the plan before the code: store the maths mark → store the science mark → add the two marks → display the total. Each step supplies information used by a later step, so their order matters.

The name total will mean combined marks, not an average or a percentage. An average of these two marks would be (40 + 35) divided by 2, which is a different rule and gives 37.5.

Follow the student’s marks through the code

This is an actual JavaScript program. Before selecting Reveal and start, predict what it will display. Then use Next step to see each instruction, its stored values and its output.

The lesson player shows a guided trace of the displayed program. It uses prepared states to explain execution. Select the second sample to see how a different science mark changes the result while the rule stays the same.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
JavaScript
const maths = 40;
const science = 35;
const total = maths + science;
console.log(total);
Live state

Top-level scope

maths→40 (number)
science→35 (number)
total→75 (number)
This step

console.log(total) displays 75. The stored values remain available after this output instruction.

Terminal
Output
75

What do you expect this program to print?

Read the four instructions without guessing

JavaScript · Maths 40 and science 35

const maths = 40;
const science = 35;
const total = maths + science;
console.log(total);

Expected output

75

This is the complete two-subject program, using maths 40 and science 35. It displays 75. Keep the code above in view as you read what each instruction means; these explanations refer to this exact sample.

const maths = 40; gives the name maths to the numeric value 40. const is a JavaScript keyword used for a name that will not be reassigned in this example. The = symbol assigns the value; it is not a question asking whether two things are equal.

const science = 35; stores the second mark under its own name. These names make the calculation easier to read. The lesson on variables and values develops this idea.

const total = maths + science; reads the stored marks, uses + to add them and assigns 75 to total. You can explore other calculations in arithmetic operators.

console.log(total); displays the value of total in the console, an output area used by JavaScript tools. The parentheses contain what should be displayed. The semicolon marks the end of each instruction in this example.

Notice the difference between calculating and displaying. After the third line, total already holds 75, but the output area is empty. The fourth line produces the visible result.

These details follow the language's const declaration rules and console.log behavior. You do not need to memorize every punctuation mark to understand the task.

Add one more subject

JavaScript · Maths 40 and science 35

const maths = 40;
const science = 35;
const total = maths + science;
console.log(total);

Expected output

75

The starting program above adds maths 40 and science 35, giving 75 out of 100. Now include a third subject in that calculation.

The student also scored 25 in English, out of 50. Update the plan so that total means combined marks across all three subjects. Predict the new total before reading the worked code.

Worked answer

Store the English mark before using it. Add all three values: 40 + 35 + 25 = 100. The possible combined score is now 150, so this is 100 out of 150, not 100 percent.

The JavaScript example below adds the new input to the calculation. Merely declaring english would not change a total that still adds only maths and science.

JavaScript · local teaching example

const maths = 40;
const science = 35;
const english = 25;
const total = maths + science + english;
console.log(total);

Expected output

100

Programs can make decisions too

In the complete program below, the student has 40 in maths and 35 in science, giving 75 out of 100. English is not part of this two-subject calculation. For a fictional classroom activity, suppose the rule is: show “Activity eligible” when the total is at least 70; otherwise show “Keep practicing”.

In JavaScript, if chooses instructions according to a condition. total >= 70 asks whether the total is greater than or equal to 70. The matching branch runs, and else handles the alternative.

Predict the message for 75, then for 60. The worked example prints Activity eligible because 75 satisfies the rule. Exactly 70 would also qualify. This is a made-up teaching rule, not a real school eligibility policy.

For a total of 60, the condition is false, so the else branch prints Keep practicing. At 70 the condition is true, because at least 70 includes 70 itself.

Programming therefore includes decisions as well as arithmetic. Learn more in conditional statements.

JavaScript · local teaching example

const maths = 40;
const science = 35;
const total = maths + science;
if (total >= 70) {
  console.log('Activity eligible');
} else {
  console.log('Keep practicing');
}

Expected output

Activity eligible

A running program can still be wrong

A teacher needs the combined marks for maths 40 and science 35, so the expected total is 75. Compare that requirement with these two complete JavaScript programs.

The wrong operation

const maths = 40;
const science = 35;
const total = maths - science;
console.log(total);

Displayed result: 5. The program subtracts 35 from 40 instead of adding them. JavaScript can execute these instructions, but the answer does not satisfy the teacher's requirement. This is a logic error: the rule in the code is wrong.

The wrong input

const maths = 40;
const science = 350;
const total = maths + science;
console.log(total);

Displayed result: 390. Addition is the intended operation, but the science mark was mistyped as 350. Each subject is out of 50, so that input is outside the permitted range. Correct arithmetic cannot make incorrect input trustworthy; a real marks form should validate the range and handle missing marks explicitly.

A computer does not automatically know which subject to include, what the maximum mark is or whether total means sum or average. Those rules must be specified. A teacher chooses the requirement; the programmer expresses and checks it.

Test a known case: 40 + 35 should be 75. Also consider zero marks, maximum marks and a missing mark. The course later explains types of programming errors, debugging techniques and testing and review.

Identify the input, work and output

JavaScript · Maths 40 and science 35

const maths = 40;
const science = 35;
const total = maths + science;
console.log(total);

Expected output

75
In the two-subject marks program, which description identifies the output?
Choose one answer. You can try again.

Answer and explanation

The total 75 displayed by console.log

Correct. The program processes the two marks and makes the resulting total visible as output.

Check the changed program

This JavaScript program stores three subject marks, but its calculation has not yet been updated to include all three. Read the complete code and predict the displayed value. Storing a mark and using it in a calculation are separate actions.

const maths = 40;
const science = 35;
const english = 25;
const total = maths + science;
console.log(total);
What does this program display?
Choose one answer. You can try again.

Answer and explanation

75, because the calculation still includes only two subjects

Correct. Storing another value does not automatically include it in a calculation; the expression must be updated.

Explain it, trace it, change it

JavaScript · Maths 40 and science 35

const maths = 40;
const science = 35;
const total = maths + science;
console.log(total);

Expected output

75

Programming turns a specified task into instructions a computer can execute. A programmer chooses the rule, writes it in a language and checks the result. Useful programs can calculate, repeat work, make decisions and respond to people.

  • Explain: our task was to calculate a student's combined marks.
  • Trace: 40 and 35 were the inputs; addition produced 75; the display instruction made 75 visible.
  • Change: adding English required a new input and an updated calculation, producing 100 out of 150.
  • Check: subtraction or an invalid mark can produce a wrong result even when the program executes.

The complete two-subject program is reproduced above as a reference. Try explaining this example to someone without reading the code aloud. Can you identify each input, name the operation and predict the output? Then change the science mark to 20 and explain why the total becomes 60.

Continue with how computers understand your code. When you want a full language-specific path, the Python course teaches these ideas using Python syntax.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: How Computers Understand Code →