LBSC 690: Session 10 Programming, JavaScript Jimmy Lin College of Information Studies University of Maryland Monday, November 12, 2007.

Slides:



Advertisements
Similar presentations
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, September 19, 2013 Session 3: JavaScript.
Advertisements

Java Script Session1 INTRODUCTION.
Programming Creating programs that run on your PC
Programming Week 9 LBSC 690 Information Technology.
CS 898N – Advanced World Wide Web Technologies Lecture 14: JavaScript Chin-Chih Chang
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Web Infrastructure Week 3 INFM 603. The Key Ideas Questions Structured Programming Modular Programming Data Structures Object-Oriented Programming.
LBSC 690 Session #10 Programming, JavaScript Jimmy Lin The iSchool University of Maryland Wednesday, November 5, 2008 This work is licensed under a Creative.
Data Structures Week 4 INFM 603. The Key Ideas Structured Programming  Modular Programming  Data Structures Object-Oriented Programming.
Programming Week 5 LBSC 690 Information Technology.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Programming Week 5 LBSC 690 Information Technology.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Computer Science 103 Chapter 4 Advanced JavaScript.
Programming Week 6 LBSC 690 Information Technology.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Introduction to a Programming Environment
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Programming Concepts and Languages Chapter 12 – Computers: Understanding Technology, 3 rd edition 1November
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
PHP: Hypertext Processor Fred Durao
INTRODUCING COMPUTER SCIENCE CSCI N341: Client-Side Programming.
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (15 questions.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
Structured Programming Week 3 INFM 603. Muddiest Points Emergent behavior of the Web HTML class attribute The details of JavaScript … p.style1 { font-family:arial;
Chapter 1: Introduction to Computers and Programming.
Generations of Programming Languages First generation  Machine Language Second Generation  Assembly Language Third Generation  Procedural language such.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
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
Introduction to Computer Systems and the Java Programming Language.
Visual C++ Programming: Concepts and Projects
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
Basic of Programming Language Skill Area Computer System Computer Program Programming Language Programmer Translators.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Programming, an introduction to Pascal
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 8 Scott Marino.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Web Programming Overview. Introduction HTML is limited - it cannot manipulate data How Web pages are extended (include): –Java: an object-oriented programming.
Tutorial 11 1 JavaScript Operators and Expressions.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Programming Session 6 LBSC 690 Information Technology.
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.
“Under the hood”: Angry Birds Maze
JavaScript.
Assembler, Compiler, Interpreter
Chapter 10 Programming Fundamentals with JavaScript
Event Driven Programming & User Defined Functions
T. Jumana Abu Shmais – AOU - Riyadh
High Level Programming Languages
Assembler, Compiler, Interpreter
Week 5 LBSC 690 Information Technology
“Under the hood”: Angry Birds Maze
Recognizing JavaScript Features
Tonga Institute of Higher Education IT 141: Information Systems
Tutorial 10: Programming with javascript
Tonga Institute of Higher Education IT 141: Information Systems
Presentation transcript:

LBSC 690: Session 10 Programming, JavaScript Jimmy Lin College of Information Studies University of Maryland Monday, November 12, 2007

Software Software “does something” Tells the machine how to operate on some data Software models aspects of reality Input and output represent the state of the world Software describes how the two are related Examples: Ballistic computations Visa’s credit card verification system Google Microsoft Word

Types of Software Application programs (e.g., PowerPoint) What you normally think of as a “software’’ Compilers and interpreters Programs used to write other programs Operating system (e.g., Windows XP) Manages computing resources Embedded software (e.g., TiVO) Programs permanently embedded inside some physical device

Programming Languages Software “does something” Programming languages tell the machine “what to do” Special purpose: geared towards specific tasks Complex math (e.g., Matlab) Databases (e.g., SQL) General purpose: able to accomplish anything Examples: Java, JavaScript, Perl, C, C++,...

Types of Programming Machine language Language that the machine can directly understand Assembly language Directly specifies actions of the machine Assembler changes instructions to machine code High-level languages Specifies machine instructions at a more abstract level Compiler/interpreter translates to machine language Examples: C/C++, Java, JavaScript Visual programming languages Visually arrange interface components Example: Visual Basic

Types of Languages Hardware Machine Language Assembly Language CJavaPascalCOBOL …

Machine Language Everything is a binary number Operations Data Memory locations For instance ADD first number (21) second number (86) 0010register

Assembly Language One level up from machine language Symbolic instructions Symbols representing memory locations For instance Assembly code is directly translatable into machine language ADD21, 86, R2

High-Level Languages Instructions represent higher-level constructs Closer to how humans approach problems Must be converted into machine code by a compiler or interpreter

Programming: Overview A program consists of a sequence of instructions Basic concepts: Data types Variables Basic operations Instructions Structures for controlling how instructions are executed: Sequential Conditional Repetition

Programming: Foundations Data types = things that you can operate on Boolean: true, false Number: 5, 9, String: “Hello World” Variables hold values of a particular data type Represented as symbols (e.g., x) Operations = things that you can do -xreverse the sign of x (negation) 6+5Add 6 and 5 (numeric) “Hello” + “World” Concatenate two strings 2.1 * 3 Multiply two values x++increase value of x by 1

Basic Instructions Assignment = store the result of an operation x = 5set the value of x to be 5 x += yx = x + y x *= 5x = x * 5 In JavaScript, var declares a variable var b = true;create a boolean b and set it to true var n = 1;create a number n and set it to 1 var s = “hello”;create a string s and set it to “hello” In JavaScript, all instructions end with a semicolon (;)

Basic Control Structures Sequential Perform instructions one after another Conditional Perform instructions contingent on something else being true Repetition Repeat instructions until a condition is met Not much different from cooking recipes!

Sequential Control Structure var a = 2; var b = 3; var c = a * b;

Conditional Control Structure if (gender == “male”) { greeting = “Hello, Sir”; } else { greeting = “Hello, Madam”; }

Test Conditions x == ytrue if x and y are equal x != y true if x and y are not equal x > ytrue if x is greater than y x <= ytrue if x is smaller than or equal to y x && ytrue if both x and y are true x || ytrue if either x or y is true !xtrue if x is false

Repetition Control Structure Program Example 1: n = 1; while ( n <= 10) { document.writeln(n); n++; } Program Example 2: For (n = 1; n <= 10; n++) { document.writeln(n); }

Arrays A set of elements grouped together For example, the number of days in each month Each element is assigned an index A number used to refer to that element For example, x[4] is the fifth element (count from zero!) Arrays and repetitions work naturally together

Functions Reusable code for doing a single task A function takes in one or more parameters and returns one value function convertToCelsius(f) { var celsius = 5/9 * (f-32); return celsius; } function weirdAddition(a, b) { var result = a + b - 0.5; return result; }

Calling Functions When you “call” a function, you invoke the set of instructions it represents c = convertToCelsius(60); function convertToCelsius(f) { var celsius = 5/9 * (f-32); return celsius; }

More Examples var f = 60; c = convertToCelsius(f); r = weirdAddition(2, 4); var a = 2; var b = 3; r = weirdAddition(a, b);

Programming Paradigms Procedural Programming Group instructions into meaningful functions Examples: C, Pascal, Perl Object oriented programming Group “data” and “methods” into “objects” Naturally represents the world around us Examples: C++, Java

Algorithms Derived from the name of the Persian mathematician Al-Khwarizmi A sequence of well-defined instructions designed to accomplish a certain task

Programming for the Web Common Gateway Interface (CGI) [Server-side] User inputs information into a form Form values passed to the sever via CGI Program on the server generates a Web page as a response JavaScript [Client-side, interpreted] Human-readable “source code” sent to the browser Web browser runs the program Java applets [Client-side, compiled] Machine-readable “bytecode” sent to browser Web browser runs the program Not related to JavaScript (other than similarities in syntax)

Where is the JavaScript? JavaScript is usually kept in the section of an HTML document … <!-- function calculate() { var num = eval(document.input.number.value); … document.output.number.value = total; } //--> …

Handling Events When does code actually get executed? Events: User actions trigger “events” Embedded in all modern GUIs Event handlers are used to respond to events Examples of event handlers in JavaScript onMouseover: the mouse moved over an object onMouseout: the mouse moved off an object onClick: the user clicked on an object

Input and Output How do you get information to/from the user? Forms provide a method for accepting input and displaying output In HTML Please enter a number: The sum of all numbers up to the number above is JavaScript code var num = eval(document.input.number.value); document.output.number.value = 10; Reads in a value eval function turns it into a number Changes the value in the textbox

JavaScript Resources Google “javascript” Tutorials: to learn to write programs Code: to do things you want to do (“borrow”) Books

Programming Tips Details are everything! Careful where you place that comma, semi-colon, etc. Write a little bit of code at a time Add a small new functionality, make sure it works, then move on Don’t try to write a large program all at once Debug by outputting the state of the program Print out the value of variables using document.write Is the value what you expected?