Stats
12 visitors online
Guests: 11
Registered: 1
12 visitors online
Guests: 11
Registered: 1
Search
Login
Website Building → Tutorials → Javascript: Strings and Variables (Part 3)
Strings are blocks of text, e.g. 'made of cheese'. Variables are numbers, like '15' or '200'.
Defining and calling variables:
<script>
a=1;
b=2;
c=a+b;
alert(c);
</script>
Arithmetic Operators
Arithmetic operators work on one or more numeric values yielding a single result.
- + Addition
- - Subtraction
- * Multiplication
- / Division
- % Modulus
- ++ Increment by 1
- -- Decrement by 1
What is Modulus?
The JavaScript Modulus Arithmetic operator returns the remainder left after division.
var a = 70 % 16;
(a is now equal to 4, since the remainder left after dividing 70 by 16 is 4)
var b = 64 % 8;
(b equals 0)
Strings
Text must be stored as a string:
<script>
var name = "Cristiano Ronaldo";
var club = 'Manchester United';
var position = "Attacking Midfielder/Forward left";
var squad_number = "7";
</script>
