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.

Slides:



Advertisements
Similar presentations
Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
Advertisements

JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Lesson 12- Unit L Programming Web Pages with JavaScript.
The Web Warrior Guide to Web Design Technologies
Tutorial 10 Programming with JavaScript
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Introduction to scripting
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
JavaScript 1. What is JavaScript? JavaScript allows web authors to create dynamic pages that react to user interaction. It is an Object-based because.
JavaScript Introduction
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
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.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Introduction to JavaScript Gordon Tian
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
JavaScript Introduction 1. What is Java Script ? JavaScript is a client-side scripting language. A scripting language is a lightweight programming language.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
JavaScript Syntax, how to use it in a HTML document
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
1 JavaScript in Context. Server-Side Programming.
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
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.
Java Script Dvijesh Bhatt. Web Page HTML defines Web sites content through semantic tags (headings, paragraphs, lists, …). CSS defines 'rules' or 'styles'
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
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.
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
CGS 3066: Web Programming and Design Spring 2017
Build in Objects In JavaScript, almost "everything" is an object.
>> Introduction to JavaScript
Programming Web Pages with JavaScript
Web Systems & Technologies
Chapter 6 JavaScript: Introduction to Scripting
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Intro to JavaScript CS 1150 Spring 2017.
My First Web Page document.write("" + Date() + ""); To insert.
JavaScript Syntax and Semantics
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript an introduction.
Objectives Insert a script element Write JavaScript comments
DHTML Javascript Internet Technology.
Your 1st Programming Assignment
WEB PROGRAMMING JavaScript.
DHTML Javascript Internet Technology.
JavaScript MCS/BCS.
Javascript.
Tutorial 10 Programming with JavaScript
Tutorial 10: Programming with javascript
JavaScript: Introduction to Scripting
Presentation transcript:

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 define the content of web pages 2. CSS to specify the layout of web pages 3. JavaScript to program the behavior of web pages

JavaScript can be placed in the and the sections of an HTML page. can be placed outside html file (External JavaScript)

JavaScript in function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } JavaScript in Head A Paragraph. Try it

JavaScript in My Web Page A Paragraph Try it function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; }

External JavaScript External JavaScript A Paragraph. Try it Note: myFunction is stored in an external file called "myScript.js". You can place an external script reference in or as you like.

External JavaScript Advantages Placing JavaScripts in external files has some advantages: It separates HTML and code It makes HTML and JavaScript easier to read and maintain Cached JavaScript files can speed up page loads

JavaScript Output JavaScript can "display" data in different ways: Writing into an alert box, using window.alert(). Writing into the HTML output using document.write(). Writing into an HTML element, using innerHTML. Writing into the browser console, using console.log().

Using window.alert() My First Web Page My first paragraph. window.alert(5 + 6);

Using document.write() My First Web Page My first paragraph. document.write(5 + 6); The document.write() method should be used only for testing.

Using document.write() My First Web Page My first paragraph. Try it The document.write() method should be used only for testing.

Using innerHTML To access an HTML element, JavaScript can use the document.getElementById(id) method. The id attribute defines the HTML element. The innerHTML property defines the HTML content:

My First Web Page My First Paragraph. document.getElementById("demo").innerHTML = 5 + 6;

Using console.log() My First Web Page My first paragraph. Activate debugging in your browser (Chrome, IE, Firefox) with F12, and select "Console" in the debugger menu. console.log(5 + 6);

JavaScript Syntax JavaScript Statements Statements are separated by semicolons. The variables x, y, and z are assigned the values 5, 6, and 11: var x = 5; var y = 6; var z = x + y; document.getElementById("demo").innerHTML = z;

JavaScript Variables JavaScript uses the var keyword to define variables. An equal sign is used to assign values to variables. var x; x = 6;

JavaScript Operators = + -* / (5 + 6) * 10

JavaScript Expressions Example 5 * 10 x * 10 "John" + " " + "Doe"

JavaScript Comments Code after double slashes // or between /* and */ is treated as a comment. var x = 5; // I will be executed // var x = 6; I will NOT be executed

JavaScript is Case Sensitive All JavaScript identifiers are case sensitive. The variables lastName and lastname, are two different variables. lastName = "Doe"; lastname = "Peterson";

JavaScript and Camel Case Hyphens: first-name, last-name, master-card, inter-city. Underscore: first_name, last_name, master_card, inter_city. Camel Case: FirstName, LastName, MasterCard, InterCity. In programming languages, especially in JavaScript, camel case often starts with a lowercase letter: firstName, lastName, masterCard, interCity.

Code Example 1 My Web Page I am a paragraph. I am a div. Try it function myFunction() { document.getElementById("myPar").innerHTML = "Hello Dolly."; document.getElementById("myDiv").innerHTML = "How are you?"; } When you click on "Try it", the two elements will change.

Code Example 2 JavaScript Operators The + operator concatenates (adds) strings. var txt1 = "John"; var txt2 = "Doe"; document.getElementById("demo").innerHTML = txt1 + " " + txt2;

JavaScript Data Types var length = 16; // Number var lastName = "Johnson"; // String var cars = ["Saab", "Volvo", "BMW"]; // Array var x = {firstName:"John", lastName:"Doe"}; // Object

Try it 1 var x = "Volvo" ; document.getElementById("demo").innerHTML = x; Results???

Try it 2 var x = "Volvo"; document.getElementById("demo").innerHTML = x; Results???

JavaScript Functions function myFunction(p1, p2) { return p1 * p2; // The function returns the product of p1 and p2 }

JavaScript Events The time is? The time is? Click the button to display the date. The time is? function displayDate() { document.getElementById("demo").innerHTML = Date(); }

JavaScript Strings var carName1 = "Volvo XC60"; var carName2 = ‘BMW’; document.getElementById("demo").innerHTML = carName1 + " " + carName2;

quotes inside a string var answer1 = "It's alright"; var answer2 = "He is called 'Johnny'"; var answer3 = 'He is called "Johnny"'; document.getElementById("demo").innerHTML = answer1 + " " + answer2 + " " + answer3;

String Length var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; document.getElementById("demo").innerHTML = txt.length;

Converting to Upper Case Convert string to upper case: Try it Hello World! function myFunction() { var text = document.getElementById("demo").innerHTML; document.getElementById("demo").innerHTML = text.toUpperCase(); }

Converting to Lower Case Convert string to lower case: Try it Hello World! function myFunction() { var text = document.getElementById("demo").innerHTML; document.getElementById("demo").innerHTML = text.toLowerCase(); }

The concat() Method The concat() method joins two or more strings: var text1 = "Hello"; var text2 = "World!"; document.getElementById("demo").innerHTML = text1.concat(" ",text2);

The charAt() Method The charAt() method returns the character at a given position in a string: var str = "HELLO WORLD"; document.getElementById("demo").innerHTML = str.charAt(0);

String to array var str = "Hello"; var arr = str.split(""); var text = ""; var i; for (i = 0; i < arr.length; i++) { text += arr[i] + " " } document.getElementById("demo").innerHTML = text;

Resources w3schools.com