Web Infrastructure Week 3 INFM 603. The Key Ideas Questions Structured Programming Modular Programming Data Structures Object-Oriented Programming.

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

More on Algorithms and Problem Solving
PSEUDOCODE & FLOW CHART
Programming TBE 540 Farah Fisher. Objectives After viewing this presentation, the learner will be able to… Given a task, create pseudocode Given pseudocode,
 Control structures  Algorithm & flowchart  If statements  While statements.
ITEC113 Algorithms and Programming Techniques
Programming Week 9 LBSC 690 Information Technology.
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
LBSC 690 Session #10 Programming, JavaScript Jimmy Lin The iSchool University of Maryland Wednesday, November 5, 2008 This work is licensed under a Creative.
1 Gentle Introduction to Programming Session 2: Functions.
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.
Program Design and Development
Programming Week 5 LBSC 690 Information Technology.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Structured Programming and UML Overview Session 2 LBSC 790 / INFM 718B Building the Human-Computer Interface.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
LBSC 690: Session 10 Programming, JavaScript Jimmy Lin College of Information Studies University of Maryland Monday, November 12, 2007.
Web Infrastructure Week 2 INFM 603. Agenda Questions XHTML CSS JavaScript.
Chapter 1 Program Design
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to Javascript. Web Page Technologies To create Web Page documents, you use: To create Web Page documents, you use: HTML – contents and structures.
Web Infrastructure Week 2 INFM 603. Agenda Questions HTML CSS JavaScript.
JS Arrays, Functions, Events Week 5 INFM 603. Agenda Arrays Functions Event-Driven Programming.
JavaScript Form Validation
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
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;
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Functions and Data Structures Week 4 INFM 603. Programming in Four Parts Structured Programming  Data Structures  Modular Programming Object-Oriented.
JavaScript Part 1.
Invitation to Computer Science, Java Version, Second Edition.
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.
Using Client-Side Scripts to Enhance Web Applications 1.
By the end of this session you should be able to...
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
ITEC113 Algorithms and Programming Techniques
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
JavaScript, Fourth Edition
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Scion Macros How to make macros for Scion The Fast and Easy Guide.
Algorithms and Pseudocode
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Data Structures Arrays and Lists Part 2 More List Operations.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
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.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
HTML & teh internets.
Programming Mehdi Bukhari.
T. Jumana Abu Shmais – AOU - Riyadh
3 Control Statements:.
Statement-Level Control Structures
Week 5 LBSC 690 Information Technology
Web Programming and Design
Intro to Programming (in JavaScript)
Presentation transcript:

Web Infrastructure Week 3 INFM 603

The Key Ideas Questions Structured Programming Modular Programming Data Structures Object-Oriented Programming

Algorithms A finite sequence of well-defined instructions designed to accomplish a certain task Named for the Persian mathematician Al-Khwarizmi

High level Languages Procedural (modular) Programming –Group instructions into meaningful abstractions –C, Pascal, Perl Object oriented programming –Group “data” and “methods” into “objects” –Naturally represents the world around us –C++, Java, JavaScript, PHP, Ruby

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

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

Conditional Selection Control Structure if (gender == “male”) { greeting = “Hello, Sir”; } else { greeting = “Hello, Madam”; } switch (gender) { case “male”: greeting = “Hello, Sir”; break; default: greeting = “Hello, Madam” }

Boolean Operators x == y true if x and y are equal [use == not =] x != y true if x and y are not equal x > ytrue if x is greater than y x <= y true 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 n = 0; while (n<10) { document.writeln(n); n++; } for (n=0; n<10; n++) { document.writeln(n); }

Key Ideas Flowcharts Pseudocode Stacking and Nesting

Group Exercise Calculate the value of a $10,000 investment at the end of each year each year from a list of annual percentage gains or losses, and make a note in each year for which a constant 5% interest rate would outperform the variable rate investment. 2001−11.9% 2002−22.1% % % % % % 2008−37.0% % %

Pair Exercises Print every even number below 873 in the Fibonacci series (see Wikipedia definition). Print a 9x9 lower triangular matrix of asterisks. Prompt the user to enter a date (number of the month and number of the day), check to see if the date is valid (assume February has 28 days), and reprompt until a valid date is entered.

Design Tips Protect against unexpected values –Test the value of all user input –Test the value of critical function parameters Verify that every loop will always terminate –Include a bailout condition, and report it Always test for conditions explicitly –Trap unexpected conditions with the final else

Programming Tips Attention to detail! –Careful where you place that comma, semicolon, etc. Don’t get cute with the logic or the layout –Reflect the structure of your problem clearly –Use standard “design patterns” Write a little bit of code at a time –Add some functionality, make sure it works, move on Debug by viewing the “state” of your program –Print values of variables using document.writeln();

Documentation Tips Reflect your pseudocode in your code –Use meaningful variable names –Use functions for abstractable concepts And name those functions well –Use comments to fill remaining gaps Add a comment to identify each revision –Give author, date, nature of the change Waste space effectively –Use indentation and blank lines to guide the eye

Arrays A set of elements –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

Using JavaScript with Forms HTML: Please enter a number: The sum of all numbers up to the number above is JavaScript: var num = eval(document.input.number.value); document.output.number.value = 10; Reads in a value from the first form (eval method turns it into a number) Changes the value in the second form

Functions (non-object “Methods”) Reusable code for complex “statements” –Takes one or more values as “parameters” –Returns at most one value as the “result” function convertToCelsius(f) { var celsius = 5/9 * (f-32); return celsius; } c = convertToCelsius(60); function convertToCelsius(f) { var celsius = 5/9 * (f-32); return celsius; } var f = 60; c = convertToCelsius(f);

Writing JavaScript Functions Convenient to put it in the section –Use to prevent display of code … <!-- function calculate() { var num = eval(document.input.number.value); … document.output.number.value = total; } //--> …

Scope of a Variable In JavaScript, var “declares” a variable var mystery;create a variable without defining its type var b = true;create a boolean b and set it to true var n = 1;create an integer n and set it to 1 var s = “hello”;create a string s and set it to “hello” Variables declared in a function are “local” Same name outside function refers to different variable All other variables are “global”

Some Useful Predefined “Methods” document.writeln(“…”); –String gets rendered as (X)HTML –Include “ ” to force a line break window.alert(“…”); –String is written verbatim as text –Include “\n” to force a line break foo = window.prompt(“…”); –String is shown verbatim as text –Result is whatever string the user enters

Handling Events Events: –Actions that users perform while visiting a page Use event handlers to response events –Event handlers triggered by 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

Before You Go On a sheet of paper, answer the following (ungraded) question (no names, please): What was the muddiest point in today’s class?