Java Script INTRODUCTION Session1
Using <Noscript>(2) • The following example shows a <NOSCRIPT> tag. <HTML> <HEAD> <SCRIPT> document.write(“Having fun”); </SCRIPT> </HEAD>
Using <Noscript>(5) Using NOSCRIPT
Displaying Information(3) for (var size = 5; size <= 100; size+=5) document.writeln(String1 + size + ‘%”>’); document.close(); } </SCRIPT></HEAD> <BODY> <FORM> <INPUT type=”button” value=”Test the loop” onclick = “doloop()” > </FORM></BODY> </HTML>
Using Alert(2) Staying Alert
Using Prompts • The prompt method is used to display a message box to accept user input. object.prompt([message[, inputDefault]]) where message - - is the string to be displayed. This is optional. Inputdefault - - is the string or integer that represents the default value of the input field.
Session 2 Data types and Operators
Data types • Every data used in program should be declared first to be of a particular type Numbers 10, - 67,14.45, -454.45 Jack, michal and joe • TRUE, FALSE Boolean values Names
Number • Comprises of Numeric Data and can be classified as • Integers ( without decimals) Eg : 123, 5040, -121 • Floating- point ( with decimals) Eg : 23.45 345.60
Floating point Numbers • Represent fractional numbers and can be positive and negative integers with exponents • Floating points numbers can be positive and negative • Example : 47.50 -123.45. 12e-2 ( 1/ 100)
Boolean Value • Results from comparison operation returns either a TRUE or FALSE. • Eg : • is 10 < 20 Returns the value True • Is Night longer than Day? Returns the value False is 10 < 20 True ? False?
String with Quotes • It can include ‘’ ( single quotes ) within double quotes and double quotes “ “ enclosed within single quotes “ John D’silva” and ‘string to display double quotes ( “” ) ’ • Escape characters are used to represent double quotes with double quotes and single quotes within single quotes “ Double Quotes \“\” ” ‘Single Quotes \‘\’ ’
\ ’ \ ” \ \ \ r \ f \ n \ b \ t Single Quote Double Quote Back Slash Carriage Return Form Feed New Line Back Space Tab List of Escape characters • Escape sequences should be used only with <PRE> </PRE> tag.
Variable Initialization • Variables can be initalized in two ways ; • During Declaration . Var sum = 0 0 is assigned to variable sum Var name = ‘Smith’ Name ‘Smith’ is assigned to variable name • After Declaration var sum Sum = 0