Содержание

Слайд 2

Which one is legal? My_variable $my_variable 1my_example _my_variable @my_variable My_variable_example ++my_variable %my_variable #my_variable ~my_variable myVariableExample

Which one is legal?

My_variable
$my_variable
1my_example
_my_variable
@my_variable
My_variable_example
++my_variable
%my_variable
#my_variable
~my_variable
myVariableExample

Слайд 3

For Loop A loop is a block of code that allows

For Loop

A loop is a block of code that allows you

to repeat a section of code a certain number of times, perhaps changing certain variable values each time the code is executed.
Слайд 4

Why loops are useful? Loops are useful because they allow you

Why loops are useful?

Loops are useful because they allow you to

repeat lines of code without retyping them or using cut and paste in your text editor.
They save time and trouble of repeatedly typing the same lines of code, but also avoids typing errors in repeated lines.
You are also able to change one or more variable values each time the browser passes through the loop.
Слайд 5

For loop for (initial_expression; test_exp; change_exp) { statements; } One of

For loop

for (initial_expression; test_exp; change_exp)
{ statements; }
One of the most used

and familiar loops is the for loop.
It iterates through a sequence of statements for a number of times controlled by a condition.
The change_exp determines how much has been added or subtracted from the counter variable.
Слайд 6

For loop for ( varname=1;varname initialization Tells the loops when to

For loop

for ( varname=1;varname<11;varname+=1 )

initialization

Tells the loops when to stop running

Determines

the rate at which the variable is changed and whether it gets larger or smaller
Слайд 7

For loop Example var counter; for (counter = 1; counter {

For loop Example


Display the square of numbers
Output: 1 4 9 16 25 36 49 64 81 100

Слайд 8

A while loop just looks at a short comparison and repeats

A while loop just looks at a short comparison and repeats

until the comparison is no longer true.
The while loop begins with a termination condition and keeps looping until the termination condition is met.
The counter variable is managed by the context of the statements inside the curly braces.
while(varname<11)
{
}

While loop

Слайд 9

While loop example While loop example var counter = 100; var

While loop example



While loop example


Слайд 10

Do…while loop The do/while loop always executes statements in the loop

Do…while loop

The do/while loop always executes statements in the loop in

the first iteration of the loop.
The termination condition is placed at the bottom of the loop.
Syntax:
do {
statements;
counter increment/decrement;
} while (termination condition)
Слайд 11

Do…while example

Do…while example

Слайд 12

Array An Array contains a set of data represented by a

Array

An Array contains a set of data represented by a single

variable name.
Arrays in JavaScript are represented by the Array Object, we need to “new Array()” to construct this object.
The first element of the array is “Array[0]” until the last one Array[i-1].
E.g. myArray = new Array(5)
We have myArray[0,1,2,3,4].
Слайд 13

Array Example Car = new Array(3); Car[0] = “Ford”; Car[1] =

Array Example


Слайд 14

Array You can also declare arrays with variable length. arrayName =

Array

You can also declare arrays with variable length.
arrayName = new Array();
Length

= 0, allows automatic extension of the length.
Car[9] = “Ford”; Car[99] = “Honda”;
Слайд 15

Events The most exciting JavaScript-powered pages are dynamic. Which means they

Events

The most exciting JavaScript-powered pages are dynamic. Which means they perform

various actions as your visitor interacts with them(moving his mouse, typing in the text, clicking things, and so on).
Events are notifications that an HTML element sends out when specific things happen
An HTML event can be something the browser does, or something a user does.
Examples
An HTML web page has finished loading
An HTML input field was changed
An HTML button was clicked
Слайд 16

Syntax

Syntax


Слайд 17

Common HTML Events The other events we can find here: https://www.w3schools.com/jsref/dom_obj_event.asp

Common HTML Events

The other events we can find here: https://www.w3schools.com/jsref/dom_obj_event.asp

Слайд 18

Example

Example

Слайд 19

Common HTML object events

Common HTML object events

Слайд 20

Onclick event

Onclick event

Слайд 21

Exercise When the button is clicked, trigger myFunction() with an event.

Exercise

When the button is clicked, trigger myFunction() with an event.

Слайд 22

Mouse Events

Mouse Events

Слайд 23

Keyboard Events

Keyboard Events

Слайд 24

onFocus event

onFocus event

Слайд 25

onblur event Execute a JavaScript when a user leaves an input field:

onblur event

Execute a JavaScript when a user leaves an input field:

Слайд 26

onchange event

onchange event

Слайд 27

Frame/Object Events

Frame/Object Events

Слайд 28

Form Events

Form Events