CHAPTER 10 JAVA SCRIPT - PowerPoint PPT Presentation

About This Presentation
Title:

CHAPTER 10 JAVA SCRIPT

Description:

JAVA SCRIPT Language that will allow you to add real programming to your web pages. Most of the browser today have their JavaScript interpreter. – PowerPoint PPT presentation

Number of Views:104
Avg rating:3.0/5.0
Slides: 25
Provided by: KEMENT7
Category:

less

Transcript and Presenter's Notes

Title: CHAPTER 10 JAVA SCRIPT


1
CHAPTER 10JAVA SCRIPT
2
JAVA SCRIPT
  • Language that will allow you to add real
    programming to your web pages.
  • Most of the browser today have their JavaScript
    interpreter.
  • We used JavaScript for
  • Browser Detection-Detecting the browser used by a
    visitor at your page.
  • Cookies- To store the information on the visitor
    computer and then retrieve this information
    automatic next time the user visit your page.
  • Control Browsers- Opening pages in customized
    windows, where you specify if the browsers
    buttons, menu line, status line or whatever
    should be present.
  • Validate Forms-Validating inputs to fields before
    submitting a form.

3
HOW TO ADD JAVA SCRIPT
  • This script tell the browser where JavaScript
    starts and ends.
  • Syntax ltScript languageJavaScriptgt
    lt/Scriptgt
  • Example
  • ltHTMLgt
  • ltBODYgt
  • ltScript language JavaScriptgt
  • //type the message/text
  • lt/Scriptgt
  • lt/BODYgt
  • lt/HTMLgt

4
IMPORTANT !
  • A few things you need to know before you write a
    JavaScript code
  • JavaScript-lines ends with a semicolon().
  • Should always put the text within .
  • If you forget to enclose your text in ,
    JavaScript will interpret your text as being
    variables rather than text.
  • Capital letter are different from non-capital
    letters.(so you need to follow the capital
    letters at exactly the right places)

5
VARIABLES
  • All variables are referred to the unique name you
    assigned to them.
  • The variable with capital letter is difference
    with variable non-capital letters.
  • Example Myname , MyName.

6
ASSIGN VALUE TO VARIABLE
  • Used equal-sign.
  • We can assign a value or text to variables.
  • Example
  • Assigned a text to variables
  • FirstNameDit4
  • Assigned a value to variables
  • a 3 a
  • Used a standard operator such as -, , and / in
    our web page.
  • We also can used , -- and operator for
    increment, decrement and returns modulus value to
    a variable.
  • Example
  • a2 ba
  • FirstNameAIM
  • LastNameAlor Setar
  • FullNameFirstName LastName

7
MESSAGE BOX
  • Three pop-up windows that we can add in our web
    pages.
  • alertbox
  • confirmbox
  • promptbox

8
ALERTBOX
  • Used when we want to make sure an information
    comes through to the user.
  • Syntax alert (text)
  • Example
  • alert(Welcome to my homepage)
  • Message box windows will provide the OK button.
  • So user need to click OK to proceed.

9
COMFIRMBOX
  • Used when we want the user to agree to or accept
    something.
  • Syntax confirm (your text)
  • Example confirm (You are 20 years old)
  • Message box window will provide the OK and
    Cancel button, so user need to click OK button
    or CANCEL button to proceed.
  • OK returns the value true
  • CANCEL returns the value false.

10
PROMPBOX
  • Used when the user should input a value before
    entering the page.
  • Example enter username, password.
  • Used together with variables.
  • Syntax
  • prompt (your text, default value)
  • Example
  • Username prompt(please enter your name,
    enter your name here)
  • User need to click OK button or CANCEL
    button after entering the text.
  • OK the promptbox returns the entry.
  • CANCEL the promptbox returns null.

11
SELECTION
  • The selection control structure in JavaScript
    are
  • If selection
  • If/else selection
  • Nested if selection
  • Multiple selection (switch)
  • Comparing operator
  • equal to
  • ! not equal to
  • lt less than
  • gt greater than
  • lt less than or equal to
  • gt greater than or equal to

12
IF SELECTION
  • Syntax
  • if (condition)action 1
  • Example
  • if (browser Mozila Firefox)
  • alert (you are using Mozila Firefox)

13
IF/ELSE SELECTION
  • Syntax
  • if (condition)action 1
  • else action 2
  • Example
  • if (browser Mozila Firefox)
  • alert (you are using Mozila Firefox)
  • else
  • alert (you are using Netscape)

14
NESTED IF
  • Example
  • a prompt(please enter first number, 0)
  • b prompt (please enter second number,
    0)
  •   if (ab)
  • if (agt0)
  • Alert (both number are equal and a is
    positive number)
  • Syntax
  • if (condition)
  • if (condition)
  • action 2
  • else
  • action 3

15
MULTIPLE SELECTION (SWITCH)
  • Is used to handle decision making.
  • Syntax
  • switch (variablename)
  • case label_1 statements_1 break
  • case label_2 statements_2 break
  • case label_n statement_n break
  • default statements

16
BOOLEAN OPERATOR
  • We call as a logical operator and use to enhance
    our if statement.
  • Example of logical operator AND (), OR ()
    and NOT (!).
  • AND - Use when we want to check if more than one
    condition to be true.
  • OR- Use when we want to check if more than one
    condition should result in the check
    being true.
  • NOT- Use to invert whatever we are checking for.

17
LOOP
  • Used to make sure we can display data for more
    then one times.
  • 3 different loop
  • for loop
  • while loop
  • do while loop

18
FOR LOOP WHILE LOOP
  • FOR LOOP
  • Used when we know in advance how many times the
    script should perform the similar task.
  • Syntax
  • for (variablestartvalue variableltendvalue
    variable variable incrementfactot)
  • WHILE LOOP
  • Used when we dont know in advance how many times
    the loop should be performed.
  • Syntax
  • while (variable ltendvalue)
  • //type the JavaScript code,increment and
    decrement

19
DO WHILE LOOP
  • Used when we dont know in advance how many times
    the loop should be performed.
  • Same with while loop, but in do.. While its test
    the condition at the end of the loop body.
  • The loop body always executed at least once.
  •  
  • Syntax
  • do
  • //type the JavaScript code
  • Increment/ decrement
  • while (variable ltendvalue)

20
FUNCTION
  • The best way to develop and maintain a large
    program is to construct it small, simple pieces
    or modules.
  • Modules in JavaScript are called functions.
  • JavaScript programs are written by combining new
    functions that the programmer writes with
    prepackaged functions and object available in
    JavaScript.
  • The prepackaged functions that belong to
    JavaScript objects (such as Math.pow and
    Math.round) are often called methods.

21
  • JavaScript provides several objects that have a
    rich collection of methods for performing common
    mathematical calculations, string manipulations,
    date and time manipulations and manipulations of
    collections of data called Arrays.
  • The programmer can write functions to define
    specific tasks that may be used at many points in
    a script (referred as a programmer-defined
    functions).
  • A function is invoked by a function call.
  • The function call specifies the function name and
    provides information (as arguments) that the
    called function needs to do its task.

22
USER DEFINED FUNCTION
  • Syntax
  • function functionname (variable1,variable2.)
  • //here goes the Javascript for the function
  • Must be type after ltscript Languagegt
  • Must be spelled exactly as function.
  • To call the function, just called the
    functionname that you give for your function.
  •  

23
ARRAY
  • An array is a group of memory location that all
    have same name and same type.
  • Array is used to help us to automate the process.
  • When using variable-array, we need to define the
    array before referring it to any of the variable.
  • 2 types of array
  • One Dimension
  • Two Dimension

24
ONE DIMENSIONAL ARRAY
  • Syntax
  • Variablenamenew Array
  • Example Assign data to array by using looping
  • var valuenew Array
  • for (number1 numberlt100 number number 1)
  • valuenumber number 10
Write a Comment
User Comments (0)
About PowerShow.com