BW Network
    Login | Register 

Stats
2 visitors online
Guests: 2
Registered: 0



SafeSurf Logo

Website BuildingTutorials → 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>

→ Forms →


  1. Introduction
  2. Part 1: Further Introduction
  3. Part 2: Basic Implementation
  4. Part 3: Strings & Variables
  5. Part 4: Forms
  6. Part 5: Login Script