ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.

Slides:



Advertisements
Similar presentations
Java Script Session1 INTRODUCTION.
Advertisements

14/11/11.  These words have special meanings in themselves  These should NOT be used as Identifiers.  For example:  Break, do, function, case, else,
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
CS 898N – Advanced World Wide Web Technologies Lecture 14: JavaScript Chin-Chih Chang
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Chapter 5: Loops and Files.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Introduction to Web Site Development Steven Emory Department of Computer Science California State University, Los Angeles Lecture 8: JavaScript I.
JavaScript Programming an Introduction Prepared By P.D. Krolak and M.S. Krolak Based on material from JavaScript Unleashed (2nd Ed)
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to JavaScript for Python Programmers
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
Javascript and the Web Whys and Hows of Javascript.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
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.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
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.
JavaScript, Fourth Edition
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Loops and Files. 5.1 The Increment and Decrement Operators.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
JavaScript, Sixth Edition
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
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 Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
PHP using MySQL Database for Web Development (part II)
>> Introduction to JavaScript
JavaScript Syntax and Semantics
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Introduction.
The structure of computer programs
Chapter 19 JavaScript.
JavaScript an introduction.
Arrays, For loop While loop Do while loop
Introduction to JavaScript for Python Programmers
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
JavaScript CS 4640 Programming Languages for Web Applications
PHP an introduction.
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

ALBERT WAVERING BOBBY SENG

Week 4: JavaScript  Quiz  Announcements/questions

What is JavaScript?  Programming language!  ‘Scripting’  Lightweight  Embedded or linked to HTML pages  No compilation  Is interpreted by a user’s browser on page load  Compatibility problems?

JavaScript’s Place …JavaScript code goes here…

JavaScript’s Place

Java vs. JavaScript  Similarities?  Syntax  Object-oriented  Differences  Everything else  Good news  Really simple to understand  Real Name?  ECMAScript  ECMA: information systems standards organization  ECMA-262 = JavaScript

Uses of JavaScript  Information processing  Updating element content  Creating interactive webpages  Moving elements  Changing visibility of elements  Asynchronous data transfer  Ex.: Facebook, Google Instant  Cookie storage/retrieval  Store user data (‘keep me logged in’, etc)

JavaScript Output to Browser  For now, use document.write(someVariable);  This is not professionally used but is good for testing and debugging  Later on we’ll be able to select elements, modify them, and generally wreak havoc

Characteristics  Normally structured with functions  If/else/while/switch/for  Dynamically typed  Variables are typed by their data  Object oriented  Objects are collections of data and functions  Fails silently  No error messages to user about code  Test each segment of code as you complete it  Use Firebug or similar

Dynamic Typing x = " Test… "; x = 5; x = 5 + 6; //x is now equal to 11

Object-Oriented Programming?  An object-oriented program allows you to make ‘objects’ and use them to store data and perform functions  An object can store variables and prototypes  You can specify a type of object, then create instances of that object with different data

Brief Intro to Objects  Declare them with name ‘function’  JS functions are objects  The keyword ‘this’ refers to elements belonging to the current object function car(color, doors, type){ this.color = color; this.doors = doors; this.type = type; } delorean = new car("silver", 2, "timetraveling");

Objects function car(color, doors, type){ this.color = color; this.doors = doors; this.type = type; this.speed = 0; this.drive = drive; } function drive(newSpeed){ this.speed = newSpeed; }

Objects delorean = new car("silver", 4, "timetraveling"); delorean.drive(88); //now delorean.speed equals 88

JavaScript Statements  Statements are ended with a semicolon  Variable = value;  Where ‘value’ is anything that evaluates to a number, string, object, etc.  Comments denoted by:  //Single line  /* Multiple-line comments are fun */

JavaScript Statements  Conditional statements and loops use code blocks  Curly brackets denote these blocks of code if(I like cookies){ do some stuff; }

Flow Control if(logical or numerical comparison){ //code executed if condition evaluates to true } else if(another comparison){ //code executed if the first condition was not //met but this one is } else{ //code executed if no other condition evaluated //to true }

Mathematical Operators  Normal arithmetic operators  Add+(combines strings too!)  Subtract -  Multiply*  Divide/  Modulus%  Increment++  Decrement--

More Math  Let x = 15  Assignment operatorsopx is:  Set to=x = 55  Add and set+=x += 520  Subtract from, set-=x -= 510  Multiply with, set*=x *= 230  Divide with, set/=x /= 53  Modulo with, set%=x /= 63

JavaScript Comparators  Logical comparisons  and&&  or||  not!  equal to ==  not equal to !=

JavaScript Comparators  Equal to==  Not equal to!=  Greater than>  Greater than or equal to>=  Less than<  Less than or equal to<=

Variable Scope  Places in the document where the variable exists to be used  Variables are global by default  Can use them anywhere  Object variables only scoped within their object  To apply local scope to a variable inside a function  Keyword ‘var’

Variable Scope  Inside a function, a local variable of the same name as a global variable takes precedence  When declaring variables inside functions, they are only local if the keyword ‘var’ is used

Variable Scope x = 5; function addFive(input){ var x = 0; return input + x; } document.write(x); document.write(" "); document.write(addFive(2));

JavaScript Loops  for(var counter = start; counter <= stop; counter++)  First statement runs once before looping starts  Middle statement evaluated at the beginning of each loop; loop continues if it is true  Last statement: performed at the end of each loop

JavaScript Loop Example for(var counter = 0; counter < 10; counter++){ document.write(counter + " Jump around! "); }

Other Looping Constructs  while(condition)  Loops until condition evaluates to false  do…while(condition)  Loops until condition evaluates to false (but always at least once)

while vs do…while while(x < 5){ some stuff } do{ some stuff }while(x < 5);

Homework  Write an HTML file that implements four JavaScript functions, defined on the next slide  Your file doesn’t actually have to perform the functions automatically; just implement and test them so they work  Due by next class (9/30)  Don’t worry about validation for now

Homework Description  function combine(x, y)  This should concatenate (combine) the strings x and y into a single string and print it  function print(words, count)  This should write the string ‘words’ as many times as is defined by the number count  function choose(x, y, z)  This should write:  x if x > y > z  y if y > x  z otherwise  function fibonnaci(n)  This should write out the Fibonacci sequence up to the n th term  ‘the first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two’ [Wikipedia]