Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.

Slides:



Advertisements
Similar presentations
Tutorial 5 Windows and Frames Section A - Working with Windows.
Advertisements

JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
The Web Warrior Guide to Web Design Technologies
Information Technology Center Hany Abdelwahab Computer Specialist.
Introduction to JavaScript for Python Programmers
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Javascript and the Web Whys and Hows of Javascript.
4.1 JavaScript Introduction
1 COMM 1213 H1 COMP 4923 X1 JavaScript 2 (Readings: Ch. 12, 13, 14 Knuckles)
Internet and Web Application Development Revision.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Loops Doing the same thing over and over and over and over and over and over…
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
The Document Object Model. Goals Understand how a JavaScript can communicate with the web page in which it “lives.” Understand how to use dot notation.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Lesson 19. JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide.
>> Introduction to JavaScript
Week 9 PHP Cookies and Session Introduction to JavaScript.
CITS1231 Web Technologies JavaScript and Document Object Model.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Using Client-Side Scripts to Enhance Web Applications 1.
Chapter 5: Windows and Frames
JavaScript - A Web Script Language Fred Durao
4.4 JavaScript (JS) Deitel Ch. 7, 8, 9, JavaScript & Java: Similarities JS (JavaScript) is case-sensitive Operators –arithmetic: unary +, unary.
Dialog boxes in JavaScript Events in JavaScript – What are they – “Which events are there?” – “How do I register event handlers to an HTML element?” –
JavaScript, Fourth Edition
Chapter 10: JavaScript Functions CIS 275—Web Application Development for Business I.
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.
1 JavaScript Part 3. Functions Allow the user to decide when a particular script should be run by the browser in stead of running as long as the page.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
IS2802 Introduction to Multimedia Applications for Business Lecture 3: JavaScript and Functions Rob Gleasure
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
1 Javascript CS , Spring What is Javascript ? Browser scripting language  Dynamic page creation  Interactive  Embedded into HTML pages.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Functions Function is a standalone block of statements that performs some tasks and returns a value. Functions must be declared before they can be used.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
CGS 3066: Web Programming and Design Spring 2016 Programming in JavaScript.
ECA 225 Applied Interactive Programming ECA 225 Applied Online Programming javascript arrays.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
5 th and 4 th ed: Chapters 9, 10, 11 SY306 Web and Databases for Cyber Operations SlideSet #7: JavaScript Functions and Arrays.
1 Lesson 6 Introducing JavaScript HTML and JavaScript BASICS, 4 th Edition.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
JavaScript 101 Lesson 6: Introduction to Functions.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Chapter 5 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
Tarik Booker CS 120 California State University, Los Angeles.
REEM ALMOTIRI Information Technology Department Majmaah University.
Third lecture Event 27/2/2016 JavaScript Tutorial.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
JavaScript Functions.
DHTML Javascript Internet Technology.
Introduction to JavaScript for Python Programmers
DHTML Javascript Internet Technology.
T. Jumana Abu Shmais – AOU - Riyadh
Functions, Regular expressions and Events
COP3530- Data Structures Javascript
Web Programming and Design
Presentation transcript:

Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects – JavaScript: A world of objects – The DOM Topic 5_2: Arrays, Functions and Objects in JavaScript By the end of this lecture you should :

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What is it? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Arrays: What does an egg carton have to do with an array??? An array is actually considered a special type of variable, capable of storing multiple values [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What is it? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Arrays: Creation

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What is it? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Arrays: Creation: Accessing the elements You refer to an element in an array by referring to the index number. Example: var fruit=new Array(”apple",”cherry",”grape"); var favourite=fruit[2]; What is the value of favourite?

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What is it? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Arrays: Changing contents Adding elements to an array: add at the end use push( ) example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi") Results in ["Banana", "Orange", "Apple", "Mango”,”kiwi’]; add at the front use unshift( ) Example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.unshift("Kiwi") Results in [“kiwi”,"Banana", "Orange", "Apple", "Mango”];

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What is it? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Arrays: Changing contents Deleting elements from an array: from end use pop( ) example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.pop( ) Results in ["Banana", "Orange", "Apple”]; From front use shift( ) Example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; Fruits. Shift( ) Results in ["Orange", "Apple", "Mango”];

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Functions: What are they? & Syntax A function is______________________? A function is a block of statements that performs some task and returns a value. Syntax for a function: function functionname() { some code to be executed }

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Functions: How they work A function is______________________? A function is an independent part of the program and it is not executed until it is called. Example in html: function myFunction() { alert("Hello World!"); } Try it 1. produces a button on web page with label ‘try it’ 3. The function makes an alert box that says ‘Hello World’ 2. when user clicks button mouse function is called

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Functions: How they work A function is______________________? Functions can have arguments. Parameters are passed to the function arguments when it is called. Function_name(parameter1,parameter2,…); function definition that receives the arguments Function_name(argument1, argument2….); function call that passes the arguments to the parameters

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Functions: How they work A function is______________________? Functions can have arguments. Parameters are passed to the function arguments when it is called. Example: htt p:// function myFunction(name,job) { alert("Welcome " + name + ", the " + job); } Click the button to call a function with arguments Try it

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Functions: How they work-variable scope Global or local variable?

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Functions: How they work -return statement A return statement, stops the function executing and returns a specified value back to where the function call was made. Can also use return to simply exit a function. function calculate(a,b,c) { var d = (a+b) * c; return d; } alert("The answer to 3+2x3 is" +calculate(3,2,3));

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Functions: Anonymous A function with no name. An anonymous function is simply a function containing the steps that you wish to perform Function( ) { //code goes here } Anonymous Functions as Variables: e.g. var greetings=function( ) ( ) is an operator indicating the function is to be called Closure: An anonymous function defined within another function (Quiqley, 2011) View example of HTML code.

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The concept of objects is programming is analogous to objects in the real world. Many elements of JavaScript as well as elements of a webpage can be considered to be objects.

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: A function is______________________? Many elements of JavaScript as well as elements of a webpage can be considered to be objects. The concept of objects is programming is analogous to objects in the real world. ObjectAttributesActions DogTailWag Bark CarTransport Model Hornhonk ObjectPropertyMethod documenttitle URL write

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: A function is______________________? Objects have associated properties and methods. ObjectAttributesActions DogTailWag Bark ObjectPropertyMethod documenttitle URL write If the world worked like javaScript, you’d get a dog to wag its tail by using dog.tail.wag( ) In JavaScript we can write to the document by using document.write()

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: Another analogy example, from w3cschools

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: In JavaScript virtually everything is an object. For example: Var myname=‘Geraldine’ Is creation of a string object Var lastname=‘Torrisi’ – this creates another instance of a string object. Example 2: A array is considered an object. In the previous topic we already encountered several methods associated with an array. What were they??

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: On w3c schools there is a comprehensive list of objects and their methods. Following is the reference for arrays:

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects:

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM Objects: e.g. a window, button or web page document Properties: e.g. document.bgcolor Methods: e.g. document.write() Events: e.g. on click

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM Each object is identified by an object name To indicate the location of an object within the hierarchy, you separate each level using a dot Dot syntax

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM Referencing Objects Your name: Your car: To access an item in a collection you can either use the number or the name of the item: document.write(" The first form's name is: " + document.forms[0].name + " "); document.write(" The first form's name is: " + document.getElementById("Form1").name + " ");

Topic 5_2: Arrays, functions and objects in JavaScript Arrays What is it? Creation Changing the contents Functions What are they? Syntax How they work Anonymous functions A quick lesson in Objects JavaScript: A world of objects The DOM Objects: The HTML DOM obj_array.asphttp:// obj_array.asp provides an excellent detailed reference to the DOM, its objects, properties and methods.

(Quiqley,2011) View the HTML document