Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

Similar documents
Princess Nourah bint Abdulrahman University. Computer Sciences Department

Place User-Defined Functions in the HEAD Section

What is PHP? [1] Figure 1 [1]

CGS 3066: Spring 2015 JavaScript Reference

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 12

Working with JavaScript

JavaScript Introduction

CSCE 120: Learning To Code

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

JavaScript Introduction

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

CSC Web Programming. Introduction to JavaScript

JavaScript CS 4640 Programming Languages for Web Applications

EXERCISE: Introduction to client side JavaScript

Chapter 2 Author Notes

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

SEEM4570 System Design and Implementation Lecture 03 JavaScript

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Chapter 17. Fundamental Concepts Expressed in JavaScript

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to the World Wide Web (cont d.) Introduction to the World Wide Web

Midterm Exam. 5. What is the character - (minus) used for in JavaScript? Give as many answers as you can.

"a computer programming language commonly used to create interactive effects within web browsers." If actors and lines are the content/html......

IDM 231. Functions, Objects and Methods

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

PHP. Interactive Web Systems

1. Cascading Style Sheet and JavaScript

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

JavaScript CS 4640 Programming Languages for Web Applications

JQuery and Javascript

Tutorial 10: Programming with JavaScript

Section 1. How to use Brackets to develop JavaScript applications

Web Site Development with HTML/JavaScrip

6.170 Laboratory in Software Engineering Java Style Guide. Overview. Descriptive names. Consistent indentation and spacing. Page 1 of 5.

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

JavaScript Functions, Objects and Array

HTML/CSS Lesson Plans

Lesson 1: Writing Your First JavaScript

Lesson 6: Introduction to Functions

COMS 469: Interactive Media II

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Lab # 2. For today s lab:

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

Fundamentals of Programming Session 4

Javascript. UNIVERSITY OF MASSACHUSETTS AMHERST CMPSCI 120 Fall 2010

COMP519 Practical 5 JavaScript (1)

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Variables and Typing

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

JAVASCRIPT - CREATING A TOC

CITS1231 Web Technologies. JavaScript

IT441. Subroutines. (a.k.a., Functions, Methods, etc.) DRAFT. Network Services Administration

PHP by Pearson Education, Inc. All Rights Reserved.

Course Outline. Introduction to java

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

JavaScript. What s wrong with JavaScript?

WINTER. Web Development. Template. PHP Variables and Constants. Lecture

CS1046 Lab 4. Timing: This lab should take you 85 to 130 minutes. Objectives: By the end of this lab you should be able to:

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Variables and Constants

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Enhancing Web Pages with JavaScript

3 The Building Blocks: Data Types, Literals, and Variables

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

What is CSS? NAME: INSERT OPENING GRAPHIC HERE:

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Web Design and Development ACS-1809

Functions in ActionScript

React. HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag.

COMS 469: Interactive Media II

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

IT 374 C# and Applications/ IT695 C# Data Structures

Week 4 Lecture 1. Expressions and Functions

c122mar413.notebook March 06, 2013

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

JScript Reference. Contents

Full file at C How to Program, 6/e Multiple Choice Test Bank

Lab 1. Purpose. Assignment. Action Items/Programming Requirements

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Expressions and Variables

CISC 1600 Lecture 2.4 Introduction to JavaScript

Chapter 1 INTRODUCTION

Student, Perfect Final Exam May 25, 2006 ID: Exam No CS-081/Vickery Page 1 of 6

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

CSC Web Technologies, Spring Web Data Exchange Formats

Session 6. JavaScript Part 1. Reading

Programming with Java

class objects instances Fields Constructors Methods static

CSS Selectors. Web Authoring and Design. Benjamin Kenwright

UNIT- 3 Introduction to C++

introjs.notebook March 02, 2014

Developing a Basic Web Page

Transcription:

CS4PM Web Aesthetics and Development WEEK 11 Objective: Understand basics of JScript Outline: a. Basics of JScript Reading: Refer to w3schools websites and use the TRY IT YOURSELF editor and play with different examples of JavaScript syntax. CS4PM Week 11 Page 1 of 6

What is Java Script JavaScript is a Scripting Language A scripting language is a lightweight programming language. JavaScript is programming code that can be inserted into HTML pages. JavaScript inserted into HTML pages, can be executed by all modern web browsers. JavaScript is easy to learn. What is Java Script used for Writing Into HTML Output Reacting to Events Changing HTML Content Changing HTML Images Changing HTML Styles Validate Input Scripts in HTML must be inserted between <script> and </script> tags. Scripts can be put in the <body> and in the <head> section of an HTML page. The <script> Tag To insert a JavaScript into an HTML page, use the <script> tag. The <script> and </script> tells where the JavaScript starts and ends. The lines between the <script> and </script> contain the JavaScript: <script> alert("my First JavaScript"); </script> Java Script can be inserted in: Between the head tag Between the Body As a Separate File Tip: For more e.g. check W3c Schools editor. CS4PM Week 11 Page 2 of 6

JavaScript Statements JavaScript statements are "commands" to the browser. The purpose of the statements is to tell the browser what to do. This JavaScript statement tells the browser to write "Hello Dolly" inside an HTML element with id="demo": document.getelementbyid("demo").innerhtml="hello Dolly"; Semicolon ; Semicolon separates JavaScript statements. Normally you add a semicolon at the end of each executable statement. Using semicolons also makes it possible to write many statements on one line. JavaScript is Case Sensitive JavaScript is case sensitive. Watch your capitalization closely when you write JavaScript statements A function getelementbyid is not the same as getelementbyid. A variable named myvariable is not the same as MyVariable. JavaScript Comments Comments will not be executed by JavaScript. Comments can be added to explain the JavaScript, or to make the code more readable. Single line comments start with //. JavaScript Multi-Line Comments Multi line comments start with /* and end with */. Java Script Variables JavaScript variables are "containers" for storing information: Example var x=5; var y=6; var z=x+y; CS4PM Week 11 Page 3 of 6

Much Like Algebra x=5 y=6 z=x+y As with algebra, JavaScript variables can be used to hold values (x=5) or expressions (z=x+y). Variable can have short names (like x and y) or more descriptive names (age, sum, totalvolume). Variable names must begin with a letter Variable names can also begin with $ and _ (but we will not use it) Variable names are case sensitive (y and Y are different variables) JavaScript Data Types JavaScript variables can also hold other types of data, like text values (name="john Doe"). In JavaScript a text like "John Doe" is called a string. There are many types of JavaScript variables, but for now, just think of numbers and strings. When you assign a text value to a variable, put double or single quotes around the value. When you assign a numeric value to a variable, do not put quotes around the value. If you put quotes around a numeric value, it will be treated as text. Example var pi=3.14; var name="john Doe"; var answer='yes I am!'; JavaScript Function Syntax A function is written as a code block (inside curly { } braces), preceded by the function keyword: function functionname() { some code to be executed } The code inside the function will be executed when "someone" calls the function. The function can be called directly when an event occurs (like when a user clicks a button), and it can be called from "anywhere" by JavaScript code. CS4PM Week 11 Page 4 of 6

Calling a Function with Arguments When you call a function, you can pass along some values to it, these values are called argumentsor parameters. These arguments can be used inside the function. You can send as many arguments as you like, separated by commas (,) myfunction(argument1,argument2) Declare the argument, as variables, when you declare the function: function myfunction(var1,var2) { some code } The variables and the arguments must be in the expected order. The first variable is given the value of the first passed argument etc. Functions With a Return Value Sometimes you want your function to return a value back to where the call was made. This is possible by using the return statement. When using the return statement, the function will stop executing, and return the specified value. Syntax function myfunction() { var x=5; return x; } The function above will return the value 5. Calling the function var myvar=myfunction(); Local JavaScript Variables A variable declared (using var) within a JavaScript function becomes LOCAL and can only be accessed from within that function. (the variable has local scope). You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared. CS4PM Week 11 Page 5 of 6

Local variables are deleted as soon as the function is completed. Global JavaScript Variables Variables declared outside a function, become GLOBAL, and all scripts and functions on the web page can access it. The Lifetime of JavaScript Variables The lifetime JavaScript variables starts when they are declared. Local variables are deleted when the function is completed. Global variables are deleted when you close the page. CS4PM Week 11 Page 6 of 6