This is down to changes that were made for new versions of ZPE.

Jamie Balfour BSc PGDE

Full stack developer

Including mathematics within a program is a simple task. JavaScript makes it easy to create a mathematical expression. This part of the tutorial will describe how to create a mathematical expression and evaluate it.

The following code sample shows how to store a Number value in a variable:

JavaScript

var x = 10; var y = 12;

Variables are not completely necessary in a mathematical expression, but for each of these examples they will be used to store the inputs and the outputs.

With these two variables, two numbers have been stored. For each of the following code samples these variables will be used.

This is a list of all of the mathematical operations that can be carried out in JavaScript as well as examples of them.

The addition operator is the `+`

symbol:

JavaScript

var x = 10; var y = 12; var z = x + y; alert(z);

Subtraction uses the `-`

symbol:

JavaScript

var x = 10; var y = 12; var z = x - y; alert(z);

Multiplication in JavaScript uses the asterisk symbol `*`

:

JavaScript

var x = 10; var y = 12; var z = x * y; alert(z);

And division uses the forward slash `/`

symbol:

JavaScript

var x = 10; var y = 12; var z = x / y; alert(z);

A final mathematical operator known as modulus performs a less well-known operation. What modulus does is it divides two numbers and returns the remainer of those two numbers. Take 10 and 12, if 12 is divided by 10 it leaves a remainder of 2:

JavaScript

var x = 10; var y = 12; var z = y % x; alert(z);

The final mathematical operation that this page discusses is the increment and decrement operations. Incrementing means increasing in steps whereas decrementing means decreasing in steps.

The increment operator is `++`

. In the following example the value will
increment after each alert. This is called post incrementing:

JavaScript

var x = 10; alert(x++); alert(x++);

The next example will show the value being increased before each alert. This is called pre incrementing:

JavaScript

var x = 10; alert(++x); alert(++x);

Decrement is the same except that the symbol changes to `--`

. The following is an example
of post decrementing:

JavaScript

var x = 10; alert(x--); alert(x--);

The following is an example of pre decrementing:

JavaScript

var x = 10; alert(--x); alert(--x);

All of these examples increase or decrease by just one. To increase or decrease a value by another number, for instance 3, a different symbol is used:

JavaScript

var x = 10; //Add and Assignment x += 3; alert(x); //Subtract and Assignment x -= 3; alert(x); //Multiply and Assignment x *= 3; alert(x); //Divide and Assignment x /= 3; alert(x);

As shown in the comments, this is called the operation and assignment, since what happens is the operation is carried out and then it is assigned to the variable.

Each of these operations are the equivalent to it's mathematical operation described previously.

Site news

The Right to Repair

Join the campaign to support the Right to Repair and make the world of electronics fairer for the consumer.

ZPE 1.8.10

ZPE 1.8.10 (Kaplan) is now available to download. Security features, a new logo, file transfer and SSH and FTP using ZPE are just some of the features it brings.

Old versions of ZPE

Older versions of ZPE can no longer connect to the ZULE repository.

This is down to changes that were made for new versions of ZPE.

This is down to changes that were made for new versions of ZPE.

New effects for BalfSlider

Several new effects have been added to BalfSlider this month. The next version of BalfSlider is also underwork.

BalfBar v1.4

The next version of BalfBar is here offering better performance and a smaller file size as well as new features.

Velocity Web Server

There is information about my new web server project, VWS, on my website.

Quick links

@mrjbbalfour

S1s and S2s really enjoyed the lesson on cybercrime using the lesson on How to Rob A Bank on… https://t.co/MxjDYE2JFu 7 months ago |

S2s doing really well in hardware test! Also really enjoying doing tests electronically rather than on paper.… https://t.co/ritdfcW6Mw 7 months ago |

S1 and S2 pupils listing input and output devices and giving answers such as keyboard and mouse but there were also… https://t.co/dGxDkYqFxo 8 months ago |

Get in touch

© Copyright Jamie B Balfour

Provide feedback on this page