WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Using Data Types (No Audio Component) © Dr. David C. Gibbs 2003-04.

Slides:



Advertisements
Similar presentations
Data Types and Operators Using Data Types
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.
Java Script Session1 INTRODUCTION.
The Web Warrior Guide to Web Design Technologies
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Forms in JavaScript (there is an audio component to this eLesson) © Dr.
PHP Introduction.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Tutorial 10 Programming with JavaScript
JavaScript, Fourth Edition
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Forms in JavaScript (NON-audio version) © Dr. David C. Gibbs
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Data Types and Operators (NON Audio Version) © Dr. David C. Gibbs
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Data Types.
1 WDMD 170 – UW Stevens Point WDMD 170 Internet Languages eLesson: CSS Introduction to Style Sheets (NON-audio version) © Dr. David C. Gibbs
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Done by: Hanadi Muhsen1 Tutorial 1.  Learn the history of JavaScript  Create a script element  Write text to a Web page with JavaScript  Understand.
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript (NON.
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
CompSci Today’s topics Java Review Just a bunch of headings meant to trigger questions A contraction of previous notes Upcoming Midterm Exam Reading.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: HTML/XHTML Tables (NON-audio version) © Dr. David C. Gibbs
JavaScript Tutorial 1 - Introduction to JavaScript WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Introduction to JavaScript – A First.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
Strings, output, quotes and comments
Variables and Data Types Data (information we're going to store) – Numbers – Text – Dates What types of data can JavaScript process? How do we store it?
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Working with Windows (No audio component) © Dr. David C. Gibbs
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
Creating Web Documents: JavaScript Ftp / file management: review Introduction to JavaScript Sources Homework: start review for midterm, work on Project.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
JavaScript and Ajax (JavaScript Data Types) Week 2 Web site:
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Java Script. introduction Today’s web sites need to go much beyond HTML. browsing through a web site, to actually interact with the web site. The web.
Introduction to JavaScript 21 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 15.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
JavaScript, Sixth Edition
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Tutorial 10 Programming with JavaScript
JavaScript, Sixth Edition
Scope, Objects, Strings, Numbers
JavaScript Syntax and Semantics
JavaScript an introduction.
WEB PROGRAMMING JavaScript.
Tutorial 10: Programming with javascript
Presentation transcript:

WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Using Data Types (No Audio Component) © Dr. David C. Gibbs

WDMD 170 – UW Stevens Point 2 Tutorial 3 Data Types and Operators Section A - Using Data Types

WDMD 170 – UW Stevens Point 3 Tutorial 3A Topics Section A - Using Data Types –What is a data type? –Two types of data: primitive and composite –How to use data types –About numeric data types –About Boolean values –How to use JavaScript objects –How to use strings –How to use arrays

WDMD 170 – UW Stevens Point 4 Why “data types”? Programs must keep track of many different types of values –e.g., time of day, person’s name, currency amount Programming languages use variables to store those values JavaScript variables are classified into categories known as data types

WDMD 170 – UW Stevens Point 5 Two Data Types in JS Primitive data types –Data types that can be assigned only a single value Reference (composite) data types –Collections of data represented by a single variable name

WDMD 170 – UW Stevens Point 6 Primitive Data Types JavaScript supports five primitive data types Numbers: Integers and floating point values Booleans Strings Undefined Null

WDMD 170 – UW Stevens Point 7 Primitive Types

WDMD 170 – UW Stevens Point 8 Peculiar Primitive Data Types Null value –Data type and a value –Signifies that the variable contains no value Undefined variable –Has never had a value assigned to it –Has not been declared or –Does not exist

WDMD 170 – UW Stevens Point 9 Reference (composite) data types Collections of data represented by a single variable name JavaScript supports three reference data types –Functions –Objects –Arrays

WDMD 170 – UW Stevens Point 10 Strong vs. Weakly “typed” data Strongly typed programming languages –Data types do not change after they have been declared (data type declaration required) –Also know as static typing Loosely typed programming languages –Variable data types are not required to be declared –Also know as dynamic typing

WDMD 170 – UW Stevens Point 11 JavaScript language –Loosely typed programming language –JavaScript does not allow data typing –Determined automatically by JavaScript interpreter Can be displayed using typeof() operator var myVar = 5; document.write(typeof(myVar)) Would display “number” Is JS data WEAKLY or STRONGLY typed?

WDMD 170 – UW Stevens Point 12 typeof() operator

WDMD 170 – UW Stevens Point 13 Refer to the instructions on pages (Gosselin). Create the file PrintDataTypes.htm and save it in your Tutorial03 folder. Preview the.htm file. Are there any surprises? eTask 1

WDMD 170 – UW Stevens Point 14 Numeric Data Types JavaScript supports two numeric data types: Integers –Positive or negative number with no decimal point –Range from –2 53 to 2 53 Floating points –Contains decimal places or written using exponential notation –Range from  X to  5 X

WDMD 170 – UW Stevens Point 15 Refer to the instructions on pages 114 (Gosselin). Create the file PrintNumbers.htm and save it in your Tutorial03 folder. Preview the.htm file. eTask 2

WDMD 170 – UW Stevens Point 16 Boolean Values Logical value of true or false –Can be thought of as yes or no, on or off, 1 or 0 Used for decision making and comparing data –Recall use in overriding internal event handler with custom code Will use them in expressions Will see operators to manipulate them

WDMD 170 – UW Stevens Point 17 Strings Text string contains zero or more characters delimited by double or single quotation marks Text strings can be: –Used as literal values: –"Hello World" –Assigned to a variable: myVar = 'Yes' –A zero-length string value (empty string): myVar = ""; //an empty string

WDMD 170 – UW Stevens Point 18 Issue: using Quotation marks in a string Using quotation marks and apostrophes JS allows paired double quotes ( "…") or single quotes ( '…') to delimit strings Use one to delimit and the other in the literal var thisString = "Dave's house"; var anotherString = 'The "house" of Dave'; Or, use escape sequence (i.e. \ ') var aThirdString = 'Dave\'s house';

WDMD 170 – UW Stevens Point 19 JavaScript escape sequences

WDMD 170 – UW Stevens Point 20 JavaScript escape sequences (2)

WDMD 170 – UW Stevens Point 21 Program sample with JS escape sequences

WDMD 170 – UW Stevens Point 22 Program sample with JS escape sequences (2)

WDMD 170 – UW Stevens Point 23 Ou tpu t of pro gra m

WDMD 170 – UW Stevens Point 24 Using HTML tags in strings Use tags to format strings –Tag must be contained inside string quotes var newString = "Dave's house. "; document.write(newString);

WDMD 170 – UW Stevens Point 25 Copy and paste the following three code samples into a new HTML document in HTML-Kit. Save the file as CarriageReturnExamples.htm in your Tutorial03 folder. //sample1 line1 = "sample 1, first line "; line2 = "sample 1, second line "; document.write(line1); document.write(line2); //sample2 line1 = "sample 2, first line\n"; line2 = "sample 2, second line\n"; document.write(line1); document.write(line2); //sample3 line1 = "sample 3, first line"; line2 = "sample 3, second line"; document.writeln(line1); document.writeln(line2); end of code samples How are the carriage returns created in each sample? eTask 3

WDMD 170 – UW Stevens Point 26 Results of eTask 3: adding carriage returns to an HTML document Which of method do you prefer? –sample 1: use of within the string –sample 2: use of escape character \n –sample 3: use of writeln() statement 2 and 3 require

WDMD 170 – UW Stevens Point 27 Arrays Contains a set of data represented by a single variable name –i.e., collection of variables contained in a single variable –Used to store related things –To create, use Array() constructor function myArrayVar = new Array(numberOfElements);

WDMD 170 – UW Stevens Point 28 Arrays - conceptually

WDMD 170 – UW Stevens Point 29 Details of Arrays Each piece of data in array is an element Numbering of elements in array starts with 0 Size of array is declared and each element in array is accessed using brackets [ ] var hospitalDepartments; hospitalDepartments = new Array(10); hospitalDepartments[0] = "Oncology";

WDMD 170 – UW Stevens Point 30 Syntax of Array Use //example 1-declare array variable var hospitalDepartments; // example 2-get a new array capable of holding 10 elements, numbered 0-9 hospitalDepartments = new Array(10); //NOTE difference in () vs [] // example 3-assign the first position the string "Oncology" hospitalDepartments[0] = "Oncology"; … // example 4-assign subsequent positions as you wish hospitalDepartments[9] = "Radiology"; // example 5-access the first position by its subscript document.writeln(hospitalDepartments[0]) //displays "Oncology"

WDMD 170 – UW Stevens Point 31 JS Array Peculiarities Arrays can contain different data types Array elements are undefined unless value is assigned Array property length –Returns the number of elements in the array

WDMD 170 – UW Stevens Point 32 Arrays can contain different data types //code sample from Gosselin page 126 multiple_types = new Array(5); multiple_types[0] = "Hello World";//string multiple_types[1] = 10;//integer multiple_types[2] = 3.156;//floating-point multiple_types[3] = true;//Boolean multiple_types[4] = null;//null

WDMD 170 – UW Stevens Point 33 Array elements are undefined unless value is assigned var myArray = new Array(5); document.write(myArray[0]);//displays “undefined”

WDMD 170 – UW Stevens Point 34 Array property length returns the number of elements in the array var myArray = new Array(5); document.write(myArray.length);//displays “5” Very useful when processing an array using a loop; specifically, the “for” loop. The length property tells you how many times to iterate through the array.

WDMD 170 – UW Stevens Point 35 Refer to the instructions on pages (Gosselin). Create the file MonthsOfYear.htm and save it in your Tutorial03 folder. Preview the.htm file. eTask 4

WDMD 170 – UW Stevens Point 36 Assignment Complete exercises #1-6, 8 on pages (Gosselin, Tutorial 03A). Attach the file for exercise 8 in a post to your eReview discussion group. Describe any difficulties you might have had in completing exercise 8. You may also post any questions (and the exercise file) to the eReview group – for discussion purposes. One week later, add each of the files to your web page in a folder labeled Tutorial03.

WDMD 170 – UW Stevens Point 37 End of eLesson Jump to the Beginning of this eLesson WDMD 170 Course Schedule D2L Courseware Site