JavaScript Lecture 2    

Instructor: Amadou O. Wane
Last update: 09/03/01

Lecture2:

UNARY vs BINARY OPERATORS
i++ is an example of a unary operator.
3 + 4 is an example of a binary operator.

COLORS
You can specify colors in several manners:
bgcolor = #cccccc  
This is an hexadecimal notation. The notation is divided in 3 pairs of 
letters and numbers. The first pair represents the color red, the next pair represents color green, and the last pair represents color blue. There are 255 different shades of red, blue, and green; which results in a maximum number of 16 million colors. Abviously most monitor could not display so many color.

JAVASCRIPT COMPARISON OPERATORS:
== equals
!= does not equal
> is greater than
>= is greater than or equal to
< is less than
<= is less than or equal to
var myAge=45;
if (myAge <18)
{document.write("You are a minor"); }
var myAge = 30;
var AdultAge= 18;

if ( AdultAge >= myAge)
{ document.write("My age greater than or equal to 18");
}
else
{ document.write("You are under age");
}
//-------------------------------------------------------------
//F = 0->59
//D = 60 ->64
//C = 65 -> 79
//B = 80 -> 89
//A = >= 90
var my_test1=90;
var my_test2=88;
var my_test3=60;
var the_grade = "F";
var the_sum = my_test1 + my_test2 + my_test3;
var the_average = parseInt(the_sum / 3 + 0.5) ;
the_average = parseInt(the_average);
document.write("the average is : " + the_average);
if ( the_average < 60)
{ the_grade = "F";
document.write("<br>The grade is " + the_grade);
}

if ( the_average >=60 && the_average <=64)
{ the_grade = "D";
document.write("<br>The grade is " + the_grade);
}


if ( the_average >=65 && the_average <=79)
{ the_grade = "C";
document.write("<br>The grade is " + the_grade);
}

if ( the_average >=80 && the_average <=89)
{ the_grade = "B";
document.write("<br>The grade is " + the_grade);
}

if ( the_average >=90)
{ the_grade = "A";
document.write("<br>The grade is " + the_grade);
}
//------------------------------------------------------------------
//JAVASCRIPT ASSIGNMENT OPERATORS
var numb1 = 10;
numb1 += 3; //numb1 = numb1 + 3
numb1++ // numb1 = numb1 + 1
numb2 = 15;
numb2 -= 7; //numb2 = numb2 - 7
numb2 *= 7; //numb2 = numb2 * 7
numb2 /= 7; //numb2 = numb2 / 7
document.write("<br>the value of numb1 is " + numb1);
//------------------------------------------------------------------
//PARSEINT() AND PARSEFLOAT() METHODS
var theAge = "30";
theAge++;
if ( theAge >18)
{ document.write("<br>theAge " + theAge);
}
else
{ document.write("<br>Nothing happens");
}
my_numb = parseInt("33.9");
document.write("<br>my_numb is " + my_numb);
my_numb2 = parseFloat ("43.33");
document.write("<br>my_numb2 is " + my_numb2);
//------------------------------------------------------------------