JavaScript Lecture 4 - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

JavaScript Lecture 4

Description:

Note: The following s give the code and the output of the ... head body script type = 'text/javascript' var watertemp=0; var waterstate='liquid' ... – PowerPoint PPT presentation

Number of Views:166
Avg rating:3.0/5.0
Slides: 19
Provided by: remusR
Category:

less

Transcript and Presenter's Notes

Title: JavaScript Lecture 4


1
JavaScript Lecture 4
  • Assignment
  • Review (examples for- if, prompts)
  • Functions
  • Note The following slides give the code and the
    output of the examples covered in class.

2
lthtmlgt ltheadgt lttitlegtIFlt/titlegt lt/headgt ltbody
gt ltscript type "text/javascript"gt var
watertemp0 var waterstate"liquid"
var description"water" if (watertemp lt
0) waterstate "frozen"
description "ice" document
.write("ltbrgtltbrgt") document.write("Watertemp
"watertemp"ltbrgt") document.write
("Waterstate "waterstate"ltbrgt")
document.write ("Description
"description) lt/scriptgt lt/bodygt lt/htmlgt
3
OUTPUT
  • Watertemp 0
  • Waterstate frozen
  • Description ice
  • Note change the value for watertemp and check
    the output

4
  • lthtmlgt
  • ltheadgt lttitlegtSIMPLE IFlt/titlegtlt/headgt
  • ltbodygt
  • ltscript type "text/javascript"gt
  • var a true
  • if (atrue)
  • document.write("true")
  • if (afalse)
  • document.write("false")
  • lt/scriptgt
  • lt/bodygt
  • lt/htmlgt

5
OUTPUT
  • true

6
  • lthtmlgt
  • ltheadgt lttitlegtSIMPLE IFlt/titlegtlt/headgt
  • ltbodygt
  • ltscript type "text/javascript"gt
  • var a true
  • if (a)
  • document.write("true")
  • if (!a)
  • document.write("false")
  • lt/scriptgt
  • lt/bodygt
  • lt/htmlgt

7
OUTPUT
  • true
  • Note The last two programs are equivalent and
    give the same output.

8
  • lthtmlgt
  • ltheadgt lttitlegtSIMPLE IFlt/titlegtlt/headgt
  • ltbodygt
  • ltscript type "text/javascript"gt
  • var a 3
  • if (a)
  • document.write("true")
  • if (!a)
  • document.write("false")
  • lt/scriptgt
  • lt/bodygt
  • lt/htmlgt

9
OUTPUT
  • true
  • Note Change the value of a to 0 and see what
    happens.

10
  • lthtmlgt
  • ltheadgt
  • lttitlegtCONFIRM IFlt/titlegt
  • lt/headgt
  • ltbodygt
  • ltscript type "text/javascript"gt
  • var a
  • a confirm("Do you want to continue?")
  • if (a)
  • alert("You chose to continue")
  • else
  • alert("You chose to NOT continue")

11
Output Confirm box
12
Output after clicking on OK
13
Output after clicking on Cancel
14
  • lthtmlgt
  • ltheadgt lttitlegtIF ELSElt/titlegtlt/headgt
  • ltbodygt
  • ltscript type"text/javascript"gt
  • var watertemp 5
  • var waterstate
  • var description
  • if (watertemp lt0)
  • waterstate "frozen"
  • description "ice"
  • else
  • waterstate "liquid"
  • description "water"

15
Output
  • Watertemp 5
  • Waterstate liquid
  • Description water

16
Function Packages for algorithms
  • Name
  • Parameters
  • Definition
  • Also known as,
  • procedures, subroutine, method etc

17
  • function name (parameter list)
  • statement list

18
  • function print ()
  • document.write(hello)
Write a Comment
User Comments (0)
About PowerShow.com