CS 330 Class 5 - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

CS 330 Class 5

Description:

Text within single or double quotes. onclick='alert('You win a car')' Exception a literal single quote: name = 'Susy's place' Concatenation via firstname = 'Mary' ... – PowerPoint PPT presentation

Number of Views:779
Avg rating:3.0/5.0
Slides: 7
Provided by: cshil
Category:
Tags: class

less

Transcript and Presenter's Notes

Title: CS 330 Class 5


1
CS 330 Class 5
  • Programming plan for today
  • More on types (Flanagan Ch 3, 11.1)
  • Dialog boxes
  • Functions

2
Data Types and Values (Ch. 3)
  • Number integer, octal, hex, float inferred from
    the context
  • var aNumber 4.5 // no typing, declaration
    optional
  • String (3.2)
  • Text within single or double quotes.
  • onclick"alert('You win a car')
  • Exception a literal single quote name Susys
    place
  • Concatenation via
  • firstname Mary
  • name firstname Smith
  • Property name.length
  • Method name.charAt(0) returns the first letter
  • See p. 518 for other string features

3
Type Conversion (CH 11.1)
  • Automatic JavaScript will attempt to convert
    values to the type needed in a context.
  • Try the following.
  • javascriptalert(hello 5), alert(35),
    alert(35)
  • Explicit (good examples on p. 165-6)
  • parseInt(aString) returns an integer at the
    beginning of aString
  • parseFloat(aString) returns a float
  • Return to add.htm.
  • We need parseint becauase form variables are all
    text.

4
JavaScript is Object-Based
  • Objects (document, forms,) have properties,
    methods, and events
  • Properties (values associated with an object)
  • theForm.theSum.value in add.htm
  • The object is theForm.theSum, the property is
    value
  • aString.length
  • The object is aString, the property is
    length
  • Methods (something done with respect to an
    object)
  • document.write(ltbrgtHello there)
  • The object is document, the method is write
  • Events
  • onclick alert(You got my goat) in alert2.htm
    is triggered by the users action. The object is
    button, the event is alert.

5
Dialog Boxes (Pop-Ups)
  • Three types alert, confirm, prompt.
  • They can be triggered
  • In an event handler alert2.htm.
  • Flanagan p 353 lists events that can
    trigger dialogs
  • 2. By code embedded in ltscriptgt tags
    confirm.htm, prompt.htm.
  • Different open another window. This returns no
    information to the page.
  • Caveat pop-ups can be annoying. Use only when
    needed.

6
Functions
  • Putting an alert in a functionfn1.htm
  • Adding a parameter fn2.htm, fn3.htm
  • More than one parameter fn4.htm
  • Returning a value fn5.htm
  • Recursion fn6.htm
  • More complex programming count.htm
Write a Comment
User Comments (0)
About PowerShow.com