JavaScript Tutorial Second lecture 22/2/2016.

Slides:



Advertisements
Similar presentations
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Advertisements

Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
CS 1150 – JavaScript Programming Lab TA – Sanjaya Wijeratne – Web Page -
آموزش طراحی وب سایت جلسه دهم – جاوا اسکریپت 1 تدریس طراحی وب برای اطلاعات بیشتر تماس بگیرید تاو شماره تماس: پست الکترونیک :
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
Conditional Statements While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
CIS 375—Web App Dev II JavaScript II.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
Logic and Control. 4-2 Decision (selection) structure: if (condition) { statement etc. } Example: if (age == 15) { document.write(“ you are a fifteen”);
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
JavaScript Javascript is a scripting language produced by Netscape for use within HTML Web pages. JavaScript is loosely based on Java and it is built into.
JavaScript, Fourth Edition
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
COMP403 Web Design JAVA SCRİPTS Tolgay KARANFİLLER.
1 Server versus Client-Side Programming Server-SideClient-Side.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
CIS 3.5 Lecture 2.3 "Introduction to JavaScript".
In God we trust Learning Java Script. Java Script JavaScript is the scripting language of the Web! JavaScript is used in millions of Web pages to improve.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
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.
Chapter 5: Intro to Scripting CIS 275—Web Application Development for Business I.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
JavaScript.
Java Script Introduction. Java Script Introduction.
CHAPTER 4 DECISIONS & LOOPS
>> Introduction to JavaScript
Web Systems & Technologies
CHAPTER 4 CLIENT SIDE SCRIPTING PART 1 OF 3
>> JavaScript: Location, Functions and Objects
HTML & teh internets.
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
JavaScript - Errors & Exceptions Handling
PHP 5 Syntax.
JavaScript Loops.
Exploring JavaScript Ch 14
My First Web Page document.write("" + Date() + ""); To insert.
WEB APPLICATION PROGRAMMING
JavaScript Syntax and Semantics
Expressions and Control Flow in JavaScript
JavaScript.
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
JavaScript: Control Statements I
Chapter 19 JavaScript.
JavaScript and Ajax (Expression and Operators)
Javascript الجافا سكربت هي لغة برمجه اذا جاز التعبیر تلعب دور حیوي وفعال في صفحات الویب من خلال القیام بوظائف قد تكون خارجیة او داخلیة بل لنكن اكثر دقة.
IF if (condition) { Process… }
Javascript: variables and parameters
The Web Wizard’s Guide To JavaScript
PHP.
My First Web Page document.write("" + Date() + ""); To insert.
Web Programming Language
Lect2 (MCS/BCS) Javascript.
Conditional Statements & Loops in JavaScript
CSC318 – DYNAMIC WEB APPLICATION DEVELOPMENT
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Software Engineering for Internet Applications
Web Programming– UFCFB Lecture 13
JAVASCRIPT HOW TO PROGRAM -2
Programming Basics Review
Presentation transcript:

JavaScript Tutorial Second lecture 22/2/2016

JavaScript in External File <html> <head> <script type="text/javascript" src="filename.js" ></script> </head> <body> ....... </body> </html> filename.js function sayHello() { alert("Hello World") }

JavaScript Variables Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows. <script type="text/javascript"> <!-- var money; var name; //--> </script>

JavaScript Variable Scope Global Variables − A global variable has global scope which means it can be defined anywhere in your JavaScript code. Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function. <html> <body onload = checkscope();> <script type = "text/javascript"> <!-- var myVar = "global"; // Declare a global variable function checkscope( ) { var myVar = "local"; // Declare a local variable document.write(myVar); } //--> </script> </body> </html>

What is an operator Let us take a simple expression 4 + 5 is equal to 9. Here 4 and 5 are calledoperands and ‘+’ is called the operator. JavaScript supports the following types of operators. Arithmetic Operators Comparision Operators Logical (or Relational) Operators Assignment Operators Conditional (or ternary) Operators

<script type="text/javascript"> <!-- var a = 33; var b = 10; document.write(result); document.write(linebreak); document.write("a % b = "); result = a % b; document.write("a + b + c = "); result = a + b + c; a = ++a; document.write("++a = "); result = ++a; b = --b; document.write("--b = "); result = --b; //--> </script> Set the variables to different values and then try... </body> </html> <html> <body> <script type="text/javascript"> <!-- var a = 33; var b = 10; var c = "Test"; var linebreak = "<br />"; document.write("a + b = "); result = a + b; document.write(result); document.write(linebreak); document.write("a - b = "); result = a - b; document.write("a / b = "); result = a / b;

JavaScript - if...else Statement if (expression){ Statement(s) to be executed if expression is true } <html> <body> <script type="text/javascript"> <!-- var age = 20; if( age > 18 ){ document.write("<b>Qualifies for driving</b>"); } //--> </script> <p>Set the variable to different value and then try...</p> </body> </html>

if...else statement: <html> <body> <script type="text/javascript"> <!-- var age = 15; if( age > 18 ){ document.write("<b>Qualifies for driving</b>"); } else{ document.write("<b>Does not qualify for driving</b>"); //--> </script> <p>Set the variable to different value and then try...</p> </body> </html>

if...else if... statement <html> <body> <script type="text/javascript"> <!-- var book = "maths"; if( book == "history" ){ document.write("<b>History Book</b>"); } else if( book == "maths" ){ document.write("<b>Maths Book</b>"); else if( book == "economics" ){ document.write("<b>Economics Book</b>"); else{ document.write("<b>Unknown Book</b>"); //--> </script> <p>Set the variable to different value and then try...</p> </body> if...else if... statement

JavaScript - Switch Case <html> <body> <script type="text/javascript"> <!-- var grade='A'; document.write("Entering switch block<br />"); switch (grade) { case 'A': document.write("Good job<br />"); break; case 'B': document.write("Pretty good<br />"); case 'C': document.write("Passed<br />"); case 'D': document.write("Not so good<br />"); case 'F': document.write("Failed<br />"); default: document.write("Unknown grade<br />") } document.write("Exiting switch block"); //--> </script> <p>Set the variable to different value and then try...</p> </body> </html> JavaScript - Switch Case

JavaScript - While Loops <html> <body> <script type="text/javascript"> <!-- var count = 0; document.write("Starting Loop "); while (count < 10){ document.write("Current Count : " + count + "<br />"); count++; } document.write("Loop stopped!"); //--> </script> <p>Set the variable to different value and then try...</p> </body> </html> JavaScript - While Loops

<html> <body> <script type="text/javascript"> <!-- var count = 0; document.write("Starting Loop" + "<br />"); do{ document.write("Current Count : " + count + "<br />"); count++; } while (count < 5); document.write ("Loop stopped!"); //--> </script> <p>Set the variable to different value and then try...</p> </body> </html> The do...while Loop

<html> <body> <script type="text/javascript"> <!-- var count; document.write("Starting Loop" + "<br />"); for(count = 0; count < 10; count++){ document.write("Current Count : " + count ); document.write("<br />"); } document.write("Loop stopped!"); //--> </script> <p>Set the variable to different value and then try...</p> </body> </html> JavaScript - For Loop

<html> <body> <script type="text/javascript"> <!-- var aProperty; document.write("Navigator Object Properties<br /> "); for (aProperty in navigator) { document.write(aProperty); document.write("<br />"); } document.write ("Exiting from the loop!"); //--> </script> <p>Set the variable to different object and then try...</p> </body> </html> JavaScript for...in loop

<html> <body> <script type="text/javascript"> <!-- var x = 1; document.write("Entering the loop<br /> "); while (x < 20) { if (x == 5){ break; // breaks out of loop completely } x = x + 1; document.write( x + "<br />"); document.write("Exiting the loop!<br /> "); //--> </script> <p>Set the variable to different value and then try...</p> </body> </html> The break Statement

<html> <body> <script type="text/javascript"> <!-- var x = 1; document.write("Entering the loop<br /> "); while (x < 10) { x = x + 1; if (x == 5){ continue; // skill rest of the loop body } document.write( x + "<br />"); document.write("Exiting the loop!<br /> "); //--> </script> <p>Set the variable to different value and then try...</p> </body> </html> The continue Statement

JavaScript - Functions <script type="text/javascript"> <!-- function sayHello() { alert("Hello there"); } //--> </script> <script type="text/javascript"> <!-- function functionname(parameter-list) { statements } //--> </script>

<html> <head> <script type="text/javascript"> function sayHello() { document.write ("Hello there!"); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type="button" onclick="sayHello()" value="Say Hello"> </form> <p>Use different text in write method and then try...</p> </body> </html Calling a Function

<html> <head> <script type="text/javascript"> function sayHello(name, age) { document.write (name + " is " + age + " years old."); } </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type="button" onclick="sayHello('Zara', 7)" value="Say Hello"> </form> <p>Use different parameters inside the function and then try...</p> </body> </html> Function Parameters

The return Statement <html> <head> <script type="text/javascript"> function concatenate(first, last) { var full; full = first + last; return full; } function secondFunction() var result; result = concatenate('Zara', 'Ali'); document.write (result ); </script> </head> <body> <p>Click the following button to call the function</p> <form> <input type="button" onclick="secondFunction()" value="Call Function"> </form> <p>Use different parameters inside the function and then try...</p> </body> </html> The return Statement