-
the javascript make the web pages more interactive we can use javascript in:
-
we can select any element, attributes, text on html using javascript for example
Select the text inside all of the <hl> elements on a page -
we can add to the content of the element, attributes, text for example
Change the size or position of an <img> element -
we can specify a set of steps for the browser to follow
-
we can specify that a script when it should be run like when a specific event has start
we can access, modify,program and react by using javascript like:
-
Slideshows
-
forms
-
reload part of a page
-
filtering data
A script is a series of instructions that a computer can follow to achieve a goal.
- to write a script we need to state the goal of the script and make list of task to achieve it in a steps:
-
DEFINE THE GOAL
-
DESIGN THE SCRIPT
-
CODE EACH STEP
- An expression evaluates into (results in) a single value, there are two types of expressions:
-
expression that just assign a value to a variable
var color = 'beige'; -
expression that use two or more values to return a single value
var area = 3 * 2; (the value is now 6)
they allow programmers to create a single value from one or more values.
- ARITHMETIC OPERATORS
perform basic math area = 3 * 2;
and we can use
| Name | Operator |
|---|---|
| addition | + |
| substraction | - |
| division | / |
| multiplication | * |
| increment | ++ |
| decrement | -- |
| modulus | % |
- STRING OPERATOR
It is used to join the strings on either side of it greeting= 'Hi' + 'Molly';
-
ASSIGNMENT OPERATORS Assign a value to a variable
color = 'black' -
COMPARISON OPERATORS
Compare two values and return true or false buy = 3 > 5; false
- LOGICAL OPERATORS
Combine expressions and return true or false buy= (5 > 3) && (2 < 4); true
functions let us group a blocks of codes together to perform a task wen can
perform the funtction that contain the block of code by calling the function
and repeated it anyware using the call function rathar than write the code again.
type of Functions:
- Expression Function:
example of the syntax
var getAge = function () {
console.log('my age is 20 years');
}
- Declaration Function
example of the syntax
function getUserName() {
var name = prompt('Hello you could you please tell me your name??');
console.log(name);
** calling the function**
we can run the code inside the curly brackets with just one line of code
getAge();
getUserName();