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

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Introducing JavaScript
Java Script Session1 INTRODUCTION.
Introduction to JavaScript
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
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.
Programming Week 5 LBSC 690 Information Technology.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
LBSC 690: Session 10 Programming, JavaScript Jimmy Lin College of Information Studies University of Maryland Monday, November 12, 2007.
The Information School of the University of Washington Oct 20fit programming1 Programming Basics INFO/CSE 100, Fall 2006 Fluency in Information Technology.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
CSS, Programming Intro Week 4 INFM 603. Agenda JavaScript Intro.
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
PHP: Hypertext Processor Fred Durao
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
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.
THE BIG PICTURE. How does JavaScript interact with the browser?
Week 9 PHP Cookies and Session Introduction to JavaScript.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Chapter 4 JavaScript and Dynamic Web pages. Objectives Static Web pages Dynamic Web pages JavaScript Variables Assignments. JavaScript Functions –(prompt(“”,””)
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
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 Session 2: What is JavaScript?
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript Syntax, how to use it in a HTML document
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, February 19, 2014 Session 4: JavaScript.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
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.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
CGS 3066: Web Programming and Design Spring 2017
Module 1 Introduction to JavaScript
>> Introduction to JavaScript
Programming Web Pages with JavaScript
“Under the hood”: Angry Birds Maze
JavaScript is a programming language designed for Web pages.
Barb Ericson Georgia Institute of Technology May 2006
WEB PROGRAMMING JavaScript.
INFO/CSE 100, Spring 2005 Fluency in Information Technology
T. Jumana Abu Shmais – AOU - Riyadh
INFO/CSE 100, Spring 2006 Fluency in Information Technology
Tutorial 10 Programming with JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript Basics What is JavaScript?
JavaScript: Introduction to Scripting
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, September 19, 2013 Session 3: JavaScript - Structured Programming

Source: Wikipedia

Types of Programming Low-level languages Directly specifies actions of the machine Example: assembly language High-level languages Specifies machine instructions at a more abstract level Compiler/interpreter translates instructions into machine actions Example: JavaScript

What’s JavaScript? Programming language for the web Client-side, runs in the browser Provides programmatic access to the HTML page in which it’s embedded (the DOM) Enables richly-interactive websites!

What’s a Document? Content Structure Appearance Behavior

Source: Iron Chef America Programming… is a lot like cooking!

Data Types and Variables 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) How should you name variables? 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”

Expressions & Statements Things that you can do: -xreverse the sign of x (negation) 6 + 5add 6 and * 3 multiply two values “Hello” + “World” concatenate two strings The simplest statements store results of expressions: x = 5set the value of x to be 5 x += yx = x + y x *= 5x = x * 5 x++increase value of x by 1 In JavaScript, statements end with a semicolon (;)

Cooking Analogy Data types are like? Variables are like? Statements are like?

Sequence of Instructions var a = 2; var b = 3; var c = a * b; Something Else Do Something Third Thing

Where does the JavaScript go? My Title … … JavaScript in the header, processed before the page is loaded JavaScript in an external file, processed before the page is loaded JavaScript in the body, processed as the page is loaded

Temperature Conversion Demo A few useful statements: var t = prompt("message here", "default"); document.writeln("message here"); console.log("message here"); alert ("message here"); Tip: what if you want to have a quote inside a quote? Your turn: Convert the temperature now Celsius to Fahrenheit

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 If it doesn’t work, revert back to previous version that worked Debug by outputting the state of the program Simulate what you think the program is doing Print out the value of variables using document.writeln or console.log Is the value what you expected? Use the Chrome JavaScript console!

Controlling Execution Conditional Loops Programming… is a lot like cooking!

Conditional if (gender == "male") { greeting = "It’s a boy!"; } else { greeting = "It’s a girl!"; } truefalse Something Else Do Something Condition Continue Note the indentation... Note, the text in red is part of the “template” of the conditional

Multiple if-else clauses if ( expression ) { … } else if ( expression ) { … } else if ( expression ) { … } else { … }

Nested if-else clauses if ( expression ) { … } else { … } } else if ( expression ) { … } else if ( expression ) { … } else { … } Note this is where indentation become important…

Test Conditions: Boolean Expressions x == ytrue if x and y are equal (note common gotcha!) 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

Creepy Guy Formula: Exercises Add some error checking Tip: x == "" Tip: exit() Add some age appropriate pictures

Loops var n = 1; while (n <= 10) { document.writeln(n); n++; } for (var n = 1; n <= 10; n++) { document.writeln(n); } true false Do Something Condition Continue FYI: Computer scientists like to start at zero… Note, the text in red is part of the “template” of the loop

Ice Cream Scoops: Exercises What happens if there’s only one scoop? Change from for loop to while loop Alternate scoops of ice cream, chocolate and vanilla Helpful tip: modulo (remainder) operation (%) 3%2 = 1, 4%2 = 0, 5%2 = 1 Randomize scoops of ice cream To generate random number between 0 and 2: Math.floor((Math.random()*3));