Mathematical Methods - Introduction to Computing - Lecture Slides, Slides of Introduction to Computing

Mathematical Methods, Event Driven Programs, Usage Guideline, JavaScript Math object, Solutions for simple problems, Drawing the x and y axes, 3 New Elements and some other key points are also part of this lecture.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

banamala
banamala 🇮🇳

4.4

(19)

114 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS101 Introduction to Computing
Lecture 35
Mathematical Methods
(Web Development Lecture 12)
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download Mathematical Methods - Introduction to Computing - Lecture Slides and more Slides Introduction to Computing in PDF only on Docsity!

CS101 Introduction to Computing

Lecture 35

Mathematical Methods

(Web Development Lecture 12)

During the last lecture we discussed Event handling

  • We looked at the concept of event-driven programs and event handlers - What are they? - What do they do? - How do we benefit from them?
  • We wrote simple programs to demonstrate the capabilities of a few event handlers

Event Driven Programs

  • Programs that can capture and respond to events are called ‘event-driven programs’
  • JavaScript was specifically designed for writing such programs

JavaScript’s Handling of Events

  • Events handlers are placed in the BODY part of a Web page as attributes in HTML tags
  • Events can be captured and responded to directly with JavaScript one-liners embedded in HTML tags in the BODY portion
  • Alternatively, events can be captured in the HTML code, and then directed to a JavaScript function for an appropriate response

In-Line JavaScript Event Handling (2)

  • Multiple JavaScript statements (separated by semicolons) can be placed in that string, but all have to fit in a single line; no newline characters are allowed in that string
  • Due to this limitation, sophisticated event handling is not possible with in-line event handling

Usage Guideline

  • For very short scripts, “all code in the tag” works well
  • The “code in the HEAD portion” is the right choice for developing larger JavaScript scripts - It makes the code easier to read - It allows the reuse of a function for multiple event handlers

onLoad & onUnload

  • onLoad executes the specified JavaScript code when a new document is loaded into a window
  • onUnload executes the specified JavaScript code when a user exits a document

A Note on Syntax (1)

  • Mixed-case capitalization of event handlers (e.g. onClick) is a convention (but not a requirement) for JavaScript event handlers defined in HTML code

Today’s Goal (Mathematical Methods)

  • We will look at JavaScript’s Math object
  • We will look at solutions for simple problems using various methods of the Math object

But first, let’s plot the sine function…

Let’s first take a look at the plot, and then we will discuss how to draw it

Sine Function Plot

(^19)

function plotSine( ) {

var ht, wd, rowN ; // rowN is the row number ht = 15 ; // height of the half cycle wd = 90 ; // width of the plot

document.write( "sin(x)" ) ;

for( rowN = ht; rowN >= -ht; rowN = rowN - 1 ) { plotRow( rowN, ht, wd ) ; } } (^20)