Changing Things

We know that we can change things, but how can each kind of variable change in JavaScript? Let’s take them one at a time.

Numbers

You can use standard math symbols to add and subtract numbers in JavaScript. Try the following in the JavaScript console:

 
5 + 2;
 
10 - 9.5;
 
23 - 46;
 
84 + -42;

You should get back the following answers (the answer is shown in the comments below the math problem).

 
5 + 2;
 
// 7
 
 
 
10 - 9.5;
 
// 0.5
 
 
23 - 46;
 
// -23
 
 
84 + -42;
 
// 42

So it even works with negative numbers. Remember this; negative numbers will be handy as we play with 3D graphics.

OK, so adding and subtracting are pretty easy in JavaScript. What about multiplication and division? There are plus and minus signs on most ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.