Skip to main content
Practice

How to Give Instructions to a Computer

Let's write some code to instruct the computer to perform simple calculations and print the results :)

Print Values to the Screen
const a = 1;
const b = 2;
const c = 3;

console.log((a + c) * b);

const is a keyword that defines constants which do not change during the execution of the program. For instance, const a = 1 assigns the value 1 to the constant a.

A keyword is a special term reserved by JavaScript that can't be used as an identifier by programmers while coding. The = is the assignment operator that sets a value to a constant.


Meaning of =

In programming, the = operator is used to assign a value rather than to convey equality as in mathematics.

Similarly, we assign the value 2 to the constant b, and 3 to the constant c.


Meaning of the Multiplication Operator *

In (a + c) * b, the asterisk (*) represents multiplication. In case you're wondering, division in most programming languages is represented by the slash (/).

So, the sum of a and c which is (a + c) is multiplied by b. The result, which is 4 * 2 = 8, is then passed to console.log.


Printing the Result

console.log is a function that outputs the value passed inside its parentheses (()). Without console.log, the result of (a + c) * b would not be displayed on the screen.

Simple, right?

That's how we can use JavaScript to instruct the computer to perform simple calculations and output the results!

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.