Académique Documents
Professionnel Documents
Culture Documents
NOTES
Programming Errors:
Syntax errors are usually typographic errors
Run-time errors usually result from illegal values, some sort of
value that is illegal (do division by 0)
Logic errors are errors in the design or implementation of the
program
Relational Operators:
Used to compare values
The result is always a Boolean value
Compare if equal ==, not equal !=, less than >, greater than <,
or equal >=.
Does not confuse equality operatot (==) with assignment (=)
Logical Operators:
Combine Boolean values in couple ways
&&
!(not)
allows for more complex conditions
only get true value if 1st and 2nd operand are true
The Conditional Statement (if statement):
if (BOOLEAN_EXPRESSION) {
STATEMENTS_IF_TRUE
}
else {
STATEMENTS_IF_FALSE
}
{} are optional for single statements(shouldnt though)
if(79<score<90)
if ((score>79)&&(score<90))
Nested IF Statements:
if statements can be nested to any depth
indentation is important for readability but the interpreter
ignores it
eliminating braces can cause subtle errors
JAVA SCRIPT FUNCTIONS
Functions:
A named block of JavaScript statements
Library Files:
A big list of function definitions
Put all function definitions is separate file with extension .js
Built in Functions and Objects:
JavaScript has built in functions
JavaScripts is object oriented language (all code is organized
into objects-variables and functions
Access them by dot notation
A lot of built in objects to use, and we can create our own objects
The Math Object:
20 mathematical functions
includes 20 useful mathematical functions including
exponentiation
o if a string is used, conversion to a number is attempted
o if conversion is impossible, function returns NaN
Useful Math Functions:
Math.sqrt(x)
Math.abs(x)
Math.floor(x)-takes a real number and always rounds it down to
the next lowest integer 1.999=1
Math.ceil(x)-always rounds up to the next highest integer
1.999=2
Math.round(x) .5=1 .4=0
Math.pow(x,y)-raises x to the y power
Maath.random()-generates a random number for us
Random Number:
Computers are deterministic, so they cant generate truly random
numbers. Only way to do it is to have some sort of device or
input into the computer that is random that comp can use.
There are algorithms that create pseudorandom numbers
The Math.random () functions utilizes one such algorithm
Math.random():
Generates a pseudo-random number xl o<=x<1
To generate a random integer between N and M:
Math.floor( (m-N+1)*Math.randm())+
The Document Object Model:
Many browser elements as well as aweb page elements are
automatically organized into an object hierarchy
The window object is the top level object
Web page elements are found in the document object
Accessing UI Elements: