JavaScript: Objects.

Slides:



Advertisements
Similar presentations
JavaScript Chapter 7 Working with Strings. String Operations (Chap 2) var colors = red blue; var colors = red blue; var sizes = small large; var sizes.
Advertisements

Presentation 8: JavaScript continued Arrays and objects Internet Technology 1.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
Notes #.9: JavaScript Object For INFS 3510, Spring 2003.
1 JavaScript/Jscript 6 Objects. 2 Introduction Up till now –JavaScript used to illustrate basic programming concepts JavaScript can also –Manipulate every.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
2 Alerts and the If/Else Conditional Statement CONTINUED There's No Right Way to Do It There are, literally, a million ways to write any given script.
Scripting Languages.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object 12.4 String Object Fundamentals of Characters and Strings.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Objects.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 13 – JavaScript/Jscript: Objects Outline 13.1Introduction 13.2Thinking About Objects 13.3.
Functions and Arrays. Predefined Functions eval(condition) –Evaluates (executes) JavaScript syntax –Eval returns an undefined value parseInt(string) and.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 10: JavaScript Functions CIS 275—Web Application Development for Business I.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Chapter 18 – JavaScript/Jscript: Objects Outline 18.1Introduction 18.2Thinking About Objects 18.3.
Session on Java script. Introduction JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet.
1 Java Strings Dr. Randy M. Kaplan. 2 Strings – 1 Characters are a fundamental data type in Java It is common to assemble characters into units called.
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
Chapter 12: Objects CIS 275—Web Application Development for Business I.
1 HTML Documents and JavaScript جاوا اسکریپت و HTML بخش هایی از جاوا اسکریپت نوشته شده توسط Tom Horton & Alfred C. Weaver تکمیل ، ویرایش و ترجمه : گروه.
OBJECTS What is an Object? Definition Properties Methods Events.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
CSS XSLT DTD JS. “How to display HTML elements” External Style Sheets can save a lot of work. External Style Sheets are stored in CSS files. id Selector:
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
Basic Objects. Math Object  Math.cos( x ), x in radians  Math.sqrt ( x )  Math.pow ( x, y )  Math.ceil( x )  etc.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Chapter 4 Java Script – Part2. 2 Location object Properties Properties href – whole path will be displayed. ex: window.location.href ( see example 11)
Java Script: Objects (Chapter 12 in [2]). 2 Outline Introduction Introduction Thinking About Objects Thinking About Objects Math Object Math Object String.
JavaScript Mimi Opkins CECS 470. What We’ll Cover Today u What is JavaScript? u What can it do? u How to program your pages using JavaScript u What do.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
JavaScript Non Primitive Datatype
11 JavaScript: Objects.
Chapter 18 – JavaScript/Jscript: Objects
JavaScript: Control Structures I
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
Chapter 17 – JavaScript/Jscript: Arrays
Chapter 4 Basics of JavaScript.
WEB APPLICATION PROGRAMMING
Introduction to Scripting
Chapter 14 - Dynamic HTML: Event Model
Chapter 12 - JavaScript: Objects
JavaScript: Arrays.
Chapter 11 - JavaScript: Arrays
Chapter 8 - JavaScript: Control Structures I
BY: SITI NURBAYA ISMAIL FACULTY of COMPUTER and MATHEMATICAL SCIENCES
Chapter 13 - Dynamic HTML: Object Model and Collections
Chapter 9 - JavaScript: Control Structures II
Chapter 24 - VBScript Outline 24.1 Introduction 24.2 Operators
JavaScript: Functions
Chapter 14 - Dynamic HTML: Event Model
Chapter 12 - JavaScript: Objects
Chapter 17 - Dynamic HTML: Structured Graphics ActiveX Control
HTML Documents and JavaScript
HTML Documents and JavaScript
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Objects.
Chapter 12 - JavaScript: Objects
JavaScript: Introduction to Scripting
Chapter 8 - JavaScript: Control Structures I
Chapter 10 - JavaScript: Functions
11 JavaScript: Objects.
Pre-AP® Computer Science Quiz
What We Want To Do User enters: Mary Smith
Presentation transcript:

JavaScript: Objects

Math Object

Math Object

Methods of the String Object

Methods of the String Object

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <!-- Fig. 12.4: CharacterProcessing.html --> 6 <!-- Character Processing Methods --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Character Processing Methods</title> 11 12 <script type = "text/javascript"> 13 <!-- 14 var s = "ZEBRA"; 15 var s2 = "AbCdEfG"; 16 17 document.writeln( "<p>Character at index 0 in '" + 18 s + "' is " + s.charAt( 0 ) ); 19 document.writeln( "<br />Character code at index 0 in '" 20 + s + "' is " + s.charCodeAt( 0 ) + "</p>" ); 21 22 document.writeln( "<p>'" + 23 String.fromCharCode( 87, 79, 82, 68 ) + 24 "' contains character codes 87, 79, 82 and 68</p>" ) 25 26 document.writeln( "<p>'" + s2 + "' in lowercase is '" + 27 s2.toLowerCase() + "'" ); 28 document.writeln( "<br />'" + s2 + "' in uppercase is '" 29 + s2.toUpperCase() + "'</p>" ); 30 // --> 31 </script> 32 33 </head><body></body> 34 </html> CharacterProcessing.html Method charAt returns a string containing the character at the specified index (0 in this example). Method charCodeAt returns the Unicode value of the character at the specified index (0 in this example). Method fromCharCode takes a comma-separated list of Unicode values and builds a string containing the character representation of those Unicode values. Methods toLowerCase and toUpperCase display versions of String s2 in all lowercase and all upper case letters, respectively.

Program Output

1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <!-- Fig. 12.5: SearchingStrings.html --> 6 <!-- Searching Strings --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title> 11 Searching Strings with indexOf and lastIndexOf 12 </title> 13 14 <script type = "text/javascript"> 15 <!-- 16 var letters = "abcdefghijklmnopqrstuvwxyzabcdefghijklm"; 17 18 function buttonPressed() 19 { 20 searchForm.first.value = 21 letters.indexOf( searchForm.inputVal.value ); 22 searchForm.last.value = 23 letters.lastIndexOf( searchForm.inputVal.value ); 24 searchForm.first12.value = 25 letters.indexOf( searchForm.inputVal.value, 12 ); 26 searchForm.last12.value = 27 letters.lastIndexOf( 28 searchForm.inputVal.value, 12 ); 29 } 30 // --> 31 </script> 32 33 </head> SearchingStrings.html Method indexOf determines the first occurrence in the string letters of the string searchForm.inputVal.value. Method lastIndexOf determines the location of the last occurrence in letters of the string in text field inputVal.

SearchingStrings.html 34 <body> 35 <form name = "searchForm" action = ""> 36 <h1>The string to search is:<br /> 37 abcdefghijklmnopqrstuvwxyzabcdefghijklm</h1> 38 <p>Enter substring to search for 39 <input name = "inputVal" type = "text" /> 40 <input name = "search" type = "button" value = "Search" 41 onclick = "buttonPressed()" /><br /></p> 42 43 <p>First occurrence located at index 44 <input name = "first" type = "text" size = "5" /> 45 <br />Last occurrence located at index 46 <input name = "last" type = "text" size = "5" /> 47 <br />First occurrence from index 12 located at index 48 <input name = "first12" type = "text" size = "5" /> 49 <br />Last occurrence from index 12 located at index 50 <input name = "last12" type = "text" size = "5" /></p> 51 </form> 52 </body> 53 </html> SearchingStrings.html

Program Output

Date Object

Date Object

Date Object

DateTime.html 1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 4 5 <!-- Fig. 12.9: DateTime.html --> 6 <!-- Date and Time Methods --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>Date and Time Methods</title> 11 12 <script type = "text/javascript"> 13 <!-- 14 var current = new Date(); 15 16 document.writeln( 17 "<h1>String representations and valueOf</h1>" ); 18 document.writeln( "toString: " + current.toString() + 19 "<br />toLocaleString: " + current.toLocaleString() + 20 "<br />toUTCString: " + current.toUTCString() + 21 "<br />valueOf: " + current.valueOf() ); 22 23 document.writeln( 24 "<h1>Get methods for local time zone</h1>" ); 25 document.writeln( "getDate: " + current.getDate() + 26 "<br />getDay: " + current.getDay() + 27 "<br />getMonth: " + current.getMonth() + 28 "<br />getFullYear: " + current.getFullYear() + 29 "<br />getTime: " + current.getTime() + 30 "<br />getHours: " + current.getHours() + 31 "<br />getMinutes: " + current.getMinutes() + 32 "<br />getSeconds: " + current.getSeconds() + 33 "<br />getMilliseconds: " + DateTime.html

DateTime.html 34 current.getMilliseconds() + 35 "<br />getTimezoneOffset: " + 36 current.getTimezoneOffset() ); 37 38 document.writeln( 39 "<h1>Specifying arguments for a new Date</h1>" ); 40 var anotherDate = new Date( 2001, 2, 18, 1, 5, 0, 0 ); 41 document.writeln( "Date: " + anotherDate ); 42 43 document.writeln( 44 "<h1>Set methods for local time zone</h1>" ); 45 anotherDate.setDate( 31 ); 46 anotherDate.setMonth( 11 ); 47 anotherDate.setFullYear( 2001 ); 48 anotherDate.setHours( 23 ); 49 anotherDate.setMinutes( 59 ); 50 anotherDate.setSeconds( 59 ); 51 document.writeln( "Modified date: " + anotherDate ); 52 // --> 53 </script> 54 55 </head><body></body> 56 </html> DateTime.html

Program Output