WEB DESIGN AND PROGRAMMING Outline 1. Introduction 2. Simple Program: Printing a Line of Text in a Web Page 3. Data types 4. Obtaining User Input with prompt Dialogs 5. Memory Concepts 6. Arithmetic 7. Decision Making: Equality and Relational Operators 8. Web Resources
WEB DESIGN AND PROGRAMMING 2 Simple Program: Printing a Line of Text in a Web Page Inline scripting – Written in the of a document – tag Indicate that the text is part of a script type attribute – Specifies the type of file and the scripting language use writeln method – Write a line in the document Escape character ( \ ) – Indicates “special” character is used in the string alert method – Dialog box
WEB DESIGN AND PROGRAMMING welcome.html (1 of 1)
WEB DESIGN AND PROGRAMMING welcome2.html (1 of 1)
2 Simple Program: Printing a Line of Text in a Web Page
WEB DESIGN AND PROGRAMMING Data types Numbers - refers to numerical values Strings - refers to one or more characters of text Booleans – True or false values Undefined or null - variables or object properties that are either undefined or do not exist
WEB DESIGN AND PROGRAMMING Numbers As the name implies, a number type refers to numerical values. Numbers can be divided into two groups: floating-point — are fractional numbers such as 2.45, -3.58, and.97 Integers — are whole numbers such as 245, - 480, and 3.
WEB DESIGN AND PROGRAMMING Boolean A Boolean value is a truth value, either 'true' or 'false', often coded 1 and 0, respectively.truth value Boolean logic allows your program to make decisions. A Boolean logic statement consists of a condition that evaluates to either true or false.
WEB DESIGN AND PROGRAMMING Undefined and Null Values The undefined type refers to those variables or object properties that are either undefined or do not exist. When a variable, for example, is declared without assigning a value to it, it is of undefined type. (eg var x;) The null type indicates an empty value. When a variable is assigned the value null, its type becomes null. – var x = null;
WEB DESIGN AND PROGRAMMING 3.1 Dynamic Welcome Page A script can adapt the content based on input from the user or other variables
WEB DESIGN AND PROGRAMMING welcome5.html (1 of 2)
WEB DESIGN AND PROGRAMMING welcome5.html (2 of 2)
WEB DESIGN AND PROGRAMMING 3.1 Dynamic Welcome Page Fig. 7.7Prompt 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.
WEB DESIGN AND PROGRAMMING 3.2 Adding Integers Prompt user for two integers and calculate the sum (Fig. 7.8) NaN (not a number) parseInt – Converts its string argument to an integer
WEB DESIGN AND PROGRAMMING Addition.html (1 of 2)
WEB DESIGN AND PROGRAMMING Addition.html (2 of 2)