Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Scripting - Introduction to Java Script - Lecture Slides, Slides of Javascript programming

Here is my collection on JavaScript lectures. It includes tutorials as well as general concepts explanations. Particularly these slides contain: Introduction to Scripting, Basic Memory Concepts, Arithmetic Operators, Decision-Making Statements, Relational and Equality Operators, Using Input and Output Stat, Simple Javascript Programs

Typology: Slides

2013/2014
On special offer
30 Points
Discount

Limited-time offer


Uploaded on 01/29/2014

surii
surii 🇮🇳

3.5

(13)

182 documents

1 / 26

Toggle sidebar
Discount

On special offer

Related documents


Partial preview of the text

Download Introduction to Scripting - Introduction to Java Script - Lecture Slides and more Slides Javascript programming in PDF only on Docsity! JavaScript: Introduction to Scripting docsity.com Topics Covered • Writing simple JavaScript programs. • Using input and output statements • Basic memory concepts. • Arithmetic operators. • Decision-making statements. • Relational and equality operators. docsity.com Scripting • Two approaches to client side scripting: • Inline scripting • Written in the <body> section of a document • JavaScript code embedded in the <head> section docsity.com Scripting • <script> tag • Indicate that the text is part of a script • type attribute • Specifies the type of file and the scripting language use: • Value: “text/javascript” • IE and Netscape use JavaScript as default scripting language • writeln method of the document object • Write a line in the document and position the cursor in the next line • Does not affect the actual rendering of the HTML document • What is being written by JavaScript is the set of html instructions that in turn determine the rendering of the html document docsity.com welcome.html (1 of 1) 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. 7.1: welcome.html --> 6 <!-- Displaying a line of text --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head> 10 <title>A First Program in JavaScript</title> 11 12 <script type = "text/javascript"> 13 <!-- 14 document.writeln( 15 "<h1>Welcome to JavaScript Programming!</h1>" ); 16 // --> 17 </script> 18 19 </head><body></body> 20 </html> HTML comment tags will result in skipping of the script by those browsers that do not support scripting docsity.com welcome4.html 1 of 1 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. 7.4: welcome4.html --> 6 <!-- Printing multiple lines in a dialog box --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 <head><title>Printing Multiple Lines in a Dialog Box</title> 10 11 <script type = "text/javascript"> 12 <!-- 13 window.alert( "Welcome to\nJavaScript\nProgramming!" ); 14 // --> 15 </script> 16 17 </head> 18 19 <body> 20 <p>Click Refresh (or Reload) to run this script again.</p> 21 </body> 22 </html> alert method of the window object displays a Dialog box docsity.com Eee Welcome to JavaScript Programming! PMP M i ea ee) eerste) nie File Edit Yiew Favorites Tools Help | Back + => » GD fa | (G@Qisearch fajFavorites (EfMedia £4 Ey & += Address je) CHT SHTPS examples) cho? welcome. html Click Refresh (or Reload) to run this script again. ig) Done Ft docsity.com Common Escape Sequences Escape sequence Description \n Newline. Position the screen cursor at the beginning of the next line. \t Horizontal tab. Move the screen cursor to the next tab stop. \r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line. Any characters output after the carriage return overwrite the characters previously output on that line. \\ Backslash. Used to represent a backslash character in a string. \" Double quote. Used to represent a double quote character in a string contained in double quotes. For example, window.alert( "\"in quotes\"" ); displays "in quotes" in an alert dialog. \' Single quote. Used to represent a single quote character in a string. For example, window.alert( '\'in quotes\'' ); displays 'in quotes' in an alert dialog. Fig. 7.5 Some common escape sequences. docsity.com 23 24 </head> 25 26 <body> 27 <p>Click Refresh (or Reload) to run this script again.</p> 28 </body> 29 </html> docsity.com Fig. 7.7 Prompt dialog displayed by the window object’s prompt method. This is the prompt to the user. This is the default value that appears when the dialog opens. This is the text field in which the user types the value. When the user clicks OK, the value typed by the user is returned to the program as a string. If the user clicks Cancel, the null value will be returned to the program and no value will be assigned to the variable. docsity.com Simple Script Example: Adding Integers • The values of numbers to be added are obtained as user inputs colleted through the window.prompt method • parseInt • Converts its string argument to an integer • What happens if the conversion is not done? • See example on our web site • NaN (not a number): value returned if non-numerical values are passed to the paresInt method docsity.com (aia eee ees x Script Prompt: Enter first integer 45 eee Eo = Script Prompt: Enter second integer [re An Addi Program er sane -/5) x| File Edit view Favorites Tools Help | eco ~ > ~ GD (2) Ab) Gisearch Ggravortes <Giimedia 24) G4~ Sh fF - |S] Address 2] C:(WSHTP3\examples|cho7 addition htm 7 Go | Links The sum is 117 Chick Refresh for Reload) to run the script again i (@) Done {[ [my computer A docsity.com Arithmetic Operators and order of evaluation JavaScript operation Arithmetic operator Algebraic expression JavaScript expression Addition + f + 7 f + 7 Subtraction - p – c p - c Multiplication * bm b * m Division / x / y or or x y x / y Remainder % r mod s r % s Fig. 7.12 Arithmetic operators. Operator(s) Operation(s) Order of evaluation (precedence) *, / or % Multiplication Division Modulus Evaluated first. If there are several such operations, they are evaluated from left to right. + or - Addition Subtraction Evaluated last. If there are several such operations, they are evaluated from left to right. Fig. 7.13 Precedence of arithmetic operators. x y -- Always use parentheses to ensure desired order of evaluation: (a + b) / 6 docsity.com Relational (Inequality and Equality) Operators Standard algebraic equality operator or relational operator JavaScript equality or relational operator Sample JavaScript condition Meaning of JavaScript condition Equality operators = == x == y x is equal to y ? != x != y x is not equal to y Relational operators > > x > y x is greater than y < < x < y x is less than y >= x >= y x is greater than or equal to y <= x <= y x is less than or equal to y Fig. 7.15 Equality and relational operators.   Do NOT confuse relational equality operator “==“ with an assignment operator “=“ docsity.com welcome6.html (3 of 3) 47 <body> 48 <p>Click Refresh (or Reload) to run this script again.</p> 49 </body> 50 </html> docsity.com Order of Precedence for the Basic Operators Operators Associativity Type * / % left to right multiplicative + - left to right additive < <= > >= left to right relational == != left to right equality = right to left assignment Fig. 7.17 Precedence and associativity of the operators discussed so far. highest lowest docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved